<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <title>LCOV - self_test2.info - network_io/unix/sockaddr.c</title>
  <link rel="stylesheet" type="text/css" href="../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../index.html">top level</a> - <a href="index.html">network_io/unix</a> - sockaddr.c<span style="font-size: 80%;"> (source / <a href="sockaddr.c.func.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">self_test2.info</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">172</td>
            <td class="headerCovTableEntry">285</td>
            <td class="headerCovTableEntryLo">60.4 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2011-07-03</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">10</td>
            <td class="headerCovTableEntry">13</td>
            <td class="headerCovTableEntryMed">76.9 %</td>
          </tr>
          <tr>
            <td></td>
            <td></td>
            <td></td>
            <td class="headerItem">Branches:</td>
            <td class="headerCovTableEntry">120</td>
            <td class="headerCovTableEntry">254</td>
            <td class="headerCovTableEntryLo">47.2 %</td>
          </tr>
          <tr><td><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">           Branch data     Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>                :            : /* Licensed to the Apache Software Foundation (ASF) under one or more</a>
<span class="lineNum">       2 </span>                :            :  * contributor license agreements.  See the NOTICE file distributed with
<span class="lineNum">       3 </span>                :            :  * this work for additional information regarding copyright ownership.
<span class="lineNum">       4 </span>                :            :  * The ASF licenses this file to You under the Apache License, Version 2.0
<span class="lineNum">       5 </span>                :            :  * (the &quot;License&quot;); you may not use this file except in compliance with
<span class="lineNum">       6 </span>                :            :  * the License.  You may obtain a copy of the License at
<span class="lineNum">       7 </span>                :            :  *
<span class="lineNum">       8 </span>                :            :  *     http://www.apache.org/licenses/LICENSE-2.0
<span class="lineNum">       9 </span>                :            :  *
<span class="lineNum">      10 </span>                :            :  * Unless required by applicable law or agreed to in writing, software
<span class="lineNum">      11 </span>                :            :  * distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<span class="lineNum">      12 </span>                :            :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<span class="lineNum">      13 </span>                :            :  * See the License for the specific language governing permissions and
<span class="lineNum">      14 </span>                :            :  * limitations under the License.
<span class="lineNum">      15 </span>                :            :  */
<span class="lineNum">      16 </span>                :            : 
<span class="lineNum">      17 </span>                :            : #include &quot;apr_arch_networkio.h&quot;
<span class="lineNum">      18 </span>                :            : #include &quot;apr_strings.h&quot;
<span class="lineNum">      19 </span>                :            : #include &quot;apr.h&quot;
<span class="lineNum">      20 </span>                :            : #include &quot;apr_lib.h&quot;
<span class="lineNum">      21 </span>                :            : #include &quot;apr_strings.h&quot;
<span class="lineNum">      22 </span>                :            : #include &quot;apr_private.h&quot;
<span class="lineNum">      23 </span>                :            : 
<span class="lineNum">      24 </span>                :            : #if APR_HAVE_STDLIB_H
<span class="lineNum">      25 </span>                :            : #include &lt;stdlib.h&gt;
<span class="lineNum">      26 </span>                :            : #endif
<span class="lineNum">      27 </span>                :            : 
<span class="lineNum">      28 </span>                :            : #define APR_WANT_STRFUNC
<span class="lineNum">      29 </span>                :            : #include &quot;apr_want.h&quot;
<span class="lineNum">      30 </span>                :            : 
<span class="lineNum">      31 </span>                :            : struct apr_ipsubnet_t {
<span class="lineNum">      32 </span>                :            :     int family;
<span class="lineNum">      33 </span>                :            : #if APR_HAVE_IPV6
<span class="lineNum">      34 </span>                :            :     apr_uint32_t sub[4]; /* big enough for IPv4 and IPv6 addresses */
<span class="lineNum">      35 </span>                :            :     apr_uint32_t mask[4];
<span class="lineNum">      36 </span>                :            : #else
<span class="lineNum">      37 </span>                :            :     apr_uint32_t sub[1];
<span class="lineNum">      38 </span>                :            :     apr_uint32_t mask[1];
<span class="lineNum">      39 </span>                :            : #endif
<span class="lineNum">      40 </span>                :            : };
<span class="lineNum">      41 </span>                :            : 
<span class="lineNum">      42 </span>                :            : #if !defined(NETWARE) &amp;&amp; !defined(WIN32)
<span class="lineNum">      43 </span>                :            : #ifdef HAVE_SET_H_ERRNO
<span class="lineNum">      44 </span>                :            : #define SET_H_ERRNO(newval) set_h_errno(newval)
<span class="lineNum">      45 </span>                :            : #else
<span class="lineNum">      46 </span>                :            : #define SET_H_ERRNO(newval) h_errno = (newval)
<span class="lineNum">      47 </span>                :            : #endif
<span class="lineNum">      48 </span>                :            : #else
<span class="lineNum">      49 </span>                :            : #define SET_H_ERRNO(newval)
<span class="lineNum">      50 </span>                :            : #endif
<span class="lineNum">      51 </span>                :            : 
<span class="lineNum">      52 </span>                :            : #if APR_HAS_THREADS &amp;&amp; !defined(GETHOSTBYNAME_IS_THREAD_SAFE) &amp;&amp; \
<span class="lineNum">      53 </span>                :            :     defined(HAVE_GETHOSTBYNAME_R)
<span class="lineNum">      54 </span>                :            : /* This is the maximum size that may be returned from the reentrant
<span class="lineNum">      55 </span>                :            :  * gethostbyname_r function.  If the system tries to use more, it
<span class="lineNum">      56 </span>                :            :  * should return ERANGE.
<span class="lineNum">      57 </span>                :            :  */
<span class="lineNum">      58 </span>                :            : #define GETHOSTBYNAME_BUFLEN 512
<span class="lineNum">      59 </span>                :            : #endif
<span class="lineNum">      60 </span>                :            : 
<span class="lineNum">      61 </span>                :            : #ifdef _WIN32_WCE
<span class="lineNum">      62 </span>                :            : /* XXX: BS solution.  Need an HAVE_GETSERVBYNAME and actually
<span class="lineNum">      63 </span>                :            :  * do something here, to provide the obvious proto mappings.
<span class="lineNum">      64 </span>                :            :  */
<span class="lineNum">      65 </span>                :            : static void *getservbyname(const char *name, const char *proto)
<span class="lineNum">      66 </span>                :            : {
<span class="lineNum">      67 </span>                :            :     return NULL;
<span class="lineNum">      68 </span>                :            : }
<span class="lineNum">      69 </span>                :            : #endif
<span class="lineNum">      70 </span>                :            : 
<a name="71"><span class="lineNum">      71 </span>                :            : static apr_status_t get_local_addr(apr_socket_t *sock)</a>
<span class="lineNum">      72 </span>                :            : {
<span class="lineNum">      73 </span>                :<span class="lineNoCov">          0 :     sock-&gt;local_addr-&gt;salen = sizeof(sock-&gt;local_addr-&gt;sa);</span>
<span class="lineNum">      74 </span>        [<span class="branchNoExec" title="Branch 1 was not executed"> # </span><span class="branchNoExec" title="Branch 2 was not executed"> # </span>]:<span class="lineNoCov">          0 :     if (getsockname(sock-&gt;socketdes, (struct sockaddr *)&amp;sock-&gt;local_addr-&gt;sa,</span>
<span class="lineNum">      75 </span>                :            :                     &amp;sock-&gt;local_addr-&gt;salen) &lt; 0) {
<span class="lineNum">      76 </span>                :<span class="lineNoCov">          0 :         return apr_get_netos_error();</span>
<span class="lineNum">      77 </span>                :            :     }
<span class="lineNum">      78 </span>                :            :     else {
<span class="lineNum">      79 </span>                :<span class="lineNoCov">          0 :         sock-&gt;local_port_unknown = sock-&gt;local_interface_unknown = 0;</span>
<span class="lineNum">      80 </span>                :            :         /* XXX assumes sin_port and sin6_port at same offset */
<span class="lineNum">      81 </span>        [<span class="branchNoExec" title="Branch 1 was not executed"> # </span><span class="branchNoExec" title="Branch 2 was not executed"> # </span>]:<span class="lineNoCov">          0 :         sock-&gt;local_addr-&gt;port = ntohs(sock-&gt;local_addr-&gt;sa.sin.sin_port);</span>
<span class="lineNum">      82 </span>                :<span class="lineNoCov">          0 :         return APR_SUCCESS;</span>
<span class="lineNum">      83 </span>                :            :     }
<span class="lineNum">      84 </span>                :            : }
<span class="lineNum">      85 </span>                :            : 
<span class="lineNum">      86 </span>                :            : static apr_status_t get_remote_addr(apr_socket_t *sock)
<span class="lineNum">      87 </span>                :            : {
<span class="lineNum">      88 </span>                :<span class="lineCov">          1 :     sock-&gt;remote_addr-&gt;salen = sizeof(sock-&gt;remote_addr-&gt;sa);</span>
<span class="lineNum">      89 </span>        [<span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchCov" title="Branch 2 was taken 1 time"> + </span>]:<span class="lineCov">          1 :     if (getpeername(sock-&gt;socketdes, (struct sockaddr *)&amp;sock-&gt;remote_addr-&gt;sa,</span>
<span class="lineNum">      90 </span>                :            :                     &amp;sock-&gt;remote_addr-&gt;salen) &lt; 0) {
<span class="lineNum">      91 </span>                :<span class="lineNoCov">          0 :         return apr_get_netos_error();</span>
<span class="lineNum">      92 </span>                :            :     }
<span class="lineNum">      93 </span>                :            :     else {
<span class="lineNum">      94 </span>                :<span class="lineCov">          1 :         sock-&gt;remote_addr_unknown = 0;</span>
<span class="lineNum">      95 </span>                :            :         /* XXX assumes sin_port and sin6_port at same offset */
<span class="lineNum">      96 </span>        [<span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchCov" title="Branch 2 was taken 1 time"> + </span>]:<span class="lineCov">          1 :         sock-&gt;remote_addr-&gt;port = ntohs(sock-&gt;remote_addr-&gt;sa.sin.sin_port);</span>
<span class="lineNum">      97 </span>                :<span class="lineCov">          1 :         return APR_SUCCESS;</span>
<span class="lineNum">      98 </span>                :            :     }
<span class="lineNum">      99 </span>                :            : }
<span class="lineNum">     100 </span>                :            : 
<a name="101"><span class="lineNum">     101 </span>                :            : APR_DECLARE(apr_status_t) apr_sockaddr_ip_getbuf(char *buf, apr_size_t buflen,</a>
<span class="lineNum">     102 </span>                :            :                                                  apr_sockaddr_t *sockaddr)
<span class="lineNum">     103 </span>                :<span class="lineCov">          6 : {</span>
<span class="lineNum">     104 </span>        [<span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchCov" title="Branch 2 was taken 6 times"> + </span>]:<span class="lineCov">          6 :     if (!apr_inet_ntop(sockaddr-&gt;family, sockaddr-&gt;ipaddr_ptr, buf, buflen)) {</span>
<span class="lineNum">     105 </span>                :<span class="lineNoCov">          0 :         return APR_ENOSPC;</span>
<span class="lineNum">     106 </span>                :            :     }
<span class="lineNum">     107 </span>                :            : 
<span class="lineNum">     108 </span>                :            : #if APR_HAVE_IPV6
<span class="lineNum">     109 </span>[<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 4 times"> + </span>][<span class="branchCov" title="Branch 2 was taken 2 times"> + </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span>]:<span class="lineCov">          8 :     if (sockaddr-&gt;family == AF_INET6 </span>
<span class="lineNum">         </span>[<span class="branchCov" title="Branch 4 was taken 2 times"> + </span><span class="branchNoCov" title="Branch 5 was not taken"> - </span>][<span class="branchCov" title="Branch 6 was taken 1 time"> + </span><span class="branchCov" title="Branch 7 was taken 1 time"> + </span>]
<span class="lineNum">         </span>        [<span class="branchCov" title="Branch 8 was taken 1 time"> + </span><span class="branchNoCov" title="Branch 9 was not taken"> - </span>]
<span class="lineNum">     110 </span>        [<span class="branchCov" title="Branch 1 was taken 2 times"> + </span><span class="branchNoCov" title="Branch 2 was not taken"> - </span>]:<span class="lineCov">          2 :         &amp;&amp; IN6_IS_ADDR_V4MAPPED((struct in6_addr *)sockaddr-&gt;ipaddr_ptr)</span>
<span class="lineNum">     111 </span>                :            :         &amp;&amp; buflen &gt; strlen(&quot;::ffff:&quot;)) {
<span class="lineNum">     112 </span>                :            :         /* This is an IPv4-mapped IPv6 address; drop the leading
<span class="lineNum">     113 </span>                :            :          * part of the address string so we're left with the familiar
<span class="lineNum">     114 </span>                :            :          * IPv4 format.
<span class="lineNum">     115 </span>                :            :          */
<span class="lineNum">     116 </span>                :<span class="lineCov">          1 :         memmove(buf, buf + strlen(&quot;::ffff:&quot;),</span>
<span class="lineNum">     117 </span>                :            :                 strlen(buf + strlen(&quot;::ffff:&quot;))+1);
<span class="lineNum">     118 </span>                :            :     }
<span class="lineNum">     119 </span>                :            : #endif
<span class="lineNum">     120 </span>                :            :     /* ensure NUL termination if the buffer is too short */
<span class="lineNum">     121 </span>                :<span class="lineCov">          6 :     buf[buflen-1] = '\0';</span>
<span class="lineNum">     122 </span>                :<span class="lineCov">          6 :     return APR_SUCCESS;</span>
<span class="lineNum">     123 </span>                :            : }
<span class="lineNum">     124 </span>                :            : 
<a name="125"><span class="lineNum">     125 </span>                :            : APR_DECLARE(apr_status_t) apr_sockaddr_ip_get(char **addr,</a>
<span class="lineNum">     126 </span>                :            :                                               apr_sockaddr_t *sockaddr)
<span class="lineNum">     127 </span>                :<span class="lineCov">          2 : {</span>
<span class="lineNum">     128 </span>                :<span class="lineCov">          2 :     *addr = apr_palloc(sockaddr-&gt;pool, sockaddr-&gt;addr_str_len);</span>
<span class="lineNum">     129 </span>                :<span class="lineCov">          2 :     return apr_sockaddr_ip_getbuf(*addr, sockaddr-&gt;addr_str_len, sockaddr);</span>
<span class="lineNum">     130 </span>                :            : }
<a name="131"><span class="lineNum">     131 </span>                :            : </a>
<span class="lineNum">     132 </span>                :            : void apr_sockaddr_vars_set(apr_sockaddr_t *addr, int family, apr_port_t port)
<span class="lineNum">     133 </span>                :<span class="lineCov">        520 : {</span>
<span class="lineNum">     134 </span>                :<span class="lineCov">        520 :     addr-&gt;family = family;</span>
<span class="lineNum">     135 </span>                :<span class="lineCov">        520 :     addr-&gt;sa.sin.sin_family = family;</span>
<span class="lineNum">     136 </span>        [<span class="branchCov" title="Branch 0 was taken 137 times"> + </span><span class="branchCov" title="Branch 1 was taken 383 times"> + </span>]:<span class="lineCov">        520 :     if (port) {</span>
<span class="lineNum">     137 </span>                :            :         /* XXX IPv6: assumes sin_port and sin6_port at same offset */
<span class="lineNum">     138 </span>        [<span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchCov" title="Branch 2 was taken 137 times"> + </span>]:<span class="lineCov">        137 :         addr-&gt;sa.sin.sin_port = htons(port);</span>
<span class="lineNum">     139 </span>                :<span class="lineCov">        137 :         addr-&gt;port = port;</span>
<span class="lineNum">     140 </span>                :            :     }
<span class="lineNum">     141 </span>                :            : 
<span class="lineNum">     142 </span>        [<span class="branchCov" title="Branch 0 was taken 496 times"> + </span><span class="branchCov" title="Branch 1 was taken 24 times"> + </span>]:<span class="lineCov">        520 :     if (family == APR_INET) {</span>
<span class="lineNum">     143 </span>                :<span class="lineCov">        496 :         addr-&gt;salen = sizeof(struct sockaddr_in);</span>
<span class="lineNum">     144 </span>                :<span class="lineCov">        496 :         addr-&gt;addr_str_len = 16;</span>
<span class="lineNum">     145 </span>                :<span class="lineCov">        496 :         addr-&gt;ipaddr_ptr = &amp;(addr-&gt;sa.sin.sin_addr);</span>
<span class="lineNum">     146 </span>                :<span class="lineCov">        496 :         addr-&gt;ipaddr_len = sizeof(struct in_addr);</span>
<span class="lineNum">     147 </span>                :            :     }
<span class="lineNum">     148 </span>                :            : #if APR_HAVE_IPV6
<span class="lineNum">     149 </span>        [<span class="branchCov" title="Branch 0 was taken 23 times"> + </span><span class="branchCov" title="Branch 1 was taken 1 time"> + </span>]:<span class="lineCov">         24 :     else if (family == APR_INET6) {</span>
<span class="lineNum">     150 </span>                :<span class="lineCov">         23 :         addr-&gt;salen = sizeof(struct sockaddr_in6);</span>
<span class="lineNum">     151 </span>                :<span class="lineCov">         23 :         addr-&gt;addr_str_len = 46;</span>
<span class="lineNum">     152 </span>                :<span class="lineCov">         23 :         addr-&gt;ipaddr_ptr = &amp;(addr-&gt;sa.sin6.sin6_addr);</span>
<span class="lineNum">     153 </span>                :<span class="lineCov">         23 :         addr-&gt;ipaddr_len = sizeof(struct in6_addr);</span>
<span class="lineNum">     154 </span>                :            :     }
<span class="lineNum">     155 </span>                :            : #endif
<span class="lineNum">     156 </span>                :<span class="lineCov">        520 : }</span>
<span class="lineNum">     157 </span>                :            : 
<span class="lineNum">     158 </span>                :            : APR_DECLARE(apr_status_t) apr_socket_addr_get(apr_sockaddr_t **sa,
<span class="lineNum">     159 </span>                :            :                                            apr_interface_e which,
<span class="lineNum">     160 </span>                :            :                                            apr_socket_t *sock)
<span class="lineNum">     161 </span>                :<span class="lineCov">          3 : {</span>
<span class="lineNum">     162 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 1 time"> + </span>]:<span class="lineCov">          3 :     if (which == APR_LOCAL) {</span>
<span class="lineNum">     163 </span>[<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>][<span class="branchNoCov" title="Branch 2 was not taken"> - </span><span class="branchCov" title="Branch 3 was taken 2 times"> + </span>]:<span class="lineCov">          2 :         if (sock-&gt;local_interface_unknown || sock-&gt;local_port_unknown) {</span>
<span class="lineNum">     164 </span>                :<span class="lineNoCov">          0 :             apr_status_t rv = get_local_addr(sock);</span>
<span class="lineNum">     165 </span>                :            : 
<span class="lineNum">     166 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :             if (rv != APR_SUCCESS) {</span>
<span class="lineNum">     167 </span>                :<span class="lineNoCov">          0 :                 return rv;</span>
<span class="lineNum">     168 </span>                :            :             }
<span class="lineNum">     169 </span>                :            :         }
<span class="lineNum">     170 </span>                :<span class="lineCov">          2 :         *sa = sock-&gt;local_addr;</span>
<span class="lineNum">     171 </span>                :            :     }
<span class="lineNum">     172 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">          1 :     else if (which == APR_REMOTE) {</span>
<span class="lineNum">     173 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">          1 :         if (sock-&gt;remote_addr_unknown) {</span>
<span class="lineNum">     174 </span>                :<span class="lineCov">          1 :             apr_status_t rv = get_remote_addr(sock);</span>
<span class="lineNum">     175 </span>                :            : 
<span class="lineNum">     176 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 1 time"> + </span>]:<span class="lineCov">          1 :             if (rv != APR_SUCCESS) {</span>
<span class="lineNum">     177 </span>                :<span class="lineNoCov">          0 :                 return rv;</span>
<span class="lineNum">     178 </span>                :            :             }
<span class="lineNum">     179 </span>                :            :         }
<span class="lineNum">     180 </span>                :<span class="lineCov">          1 :         *sa = sock-&gt;remote_addr;</span>
<span class="lineNum">     181 </span>                :            :     }
<span class="lineNum">     182 </span>                :            :     else {
<span class="lineNum">     183 </span>                :<span class="lineNoCov">          0 :         *sa = NULL;</span>
<span class="lineNum">     184 </span>                :<span class="lineNoCov">          0 :         return APR_EINVAL;</span>
<span class="lineNum">     185 </span>                :            :     }
<span class="lineNum">     186 </span>                :<span class="lineCov">          3 :     return APR_SUCCESS;</span>
<span class="lineNum">     187 </span>                :            : }
<span class="lineNum">     188 </span>                :            : 
<span class="lineNum">     189 </span>                :            : APR_DECLARE(apr_status_t) apr_parse_addr_port(char **addr,
<span class="lineNum">     190 </span>                :            :                                               char **scope_id,
<span class="lineNum">     191 </span>                :            :                                               apr_port_t *port,
<a name="192"><span class="lineNum">     192 </span>                :            :                                               const char *str,</a>
<span class="lineNum">     193 </span>                :            :                                               apr_pool_t *p)
<span class="lineNum">     194 </span>                :<span class="lineNoCov">          0 : {</span>
<span class="lineNum">     195 </span>                :            :     const char *ch, *lastchar;
<span class="lineNum">     196 </span>                :            :     int big_port;
<span class="lineNum">     197 </span>                :            :     apr_size_t addrlen;
<span class="lineNum">     198 </span>                :            : 
<span class="lineNum">     199 </span>                :<span class="lineNoCov">          0 :     *addr = NULL;         /* assume not specified */</span>
<span class="lineNum">     200 </span>                :<span class="lineNoCov">          0 :     *scope_id = NULL;     /* assume not specified */</span>
<span class="lineNum">     201 </span>                :<span class="lineNoCov">          0 :     *port = 0;            /* assume not specified */</span>
<span class="lineNum">     202 </span>                :            : 
<span class="lineNum">     203 </span>                :            :     /* First handle the optional port number.  That may be all that
<span class="lineNum">     204 </span>                :            :      * is specified in the string.
<span class="lineNum">     205 </span>                :            :      */
<span class="lineNum">     206 </span>                :<span class="lineNoCov">          0 :     ch = lastchar = str + strlen(str) - 1;</span>
<span class="lineNum">     207 </span>[<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>][<span class="branchNoExec" title="Branch 3 was not executed"> # </span><span class="branchNoExec" title="Branch 4 was not executed"> # </span>]:<span class="lineNoCov">          0 :     while (ch &gt;= str &amp;&amp; apr_isdigit(*ch)) {</span>
<span class="lineNum">     208 </span>                :<span class="lineNoCov">          0 :         --ch;</span>
<span class="lineNum">     209 </span>                :            :     }
<span class="lineNum">     210 </span>                :            : 
<span class="lineNum">     211 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :     if (ch &lt; str) {       /* Entire string is the port. */</span>
<span class="lineNum">     212 </span>                :            :         big_port = atoi(str);
<span class="lineNum">     213 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (big_port &lt; 1 || big_port &gt; 65535) {</span>
<span class="lineNum">     214 </span>                :<span class="lineNoCov">          0 :             return APR_EINVAL;</span>
<span class="lineNum">     215 </span>                :            :         }
<span class="lineNum">     216 </span>                :<span class="lineNoCov">          0 :         *port = big_port;</span>
<span class="lineNum">     217 </span>                :<span class="lineNoCov">          0 :         return APR_SUCCESS;</span>
<span class="lineNum">     218 </span>                :            :     }
<span class="lineNum">     219 </span>                :            : 
<span class="lineNum">     220 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :     if (*ch == ':' &amp;&amp; ch &lt; lastchar) { /* host and port number specified */</span>
<span class="lineNum">     221 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (ch == str) {               /* string starts with ':' -- bad */</span>
<span class="lineNum">     222 </span>                :<span class="lineNoCov">          0 :             return APR_EINVAL;</span>
<span class="lineNum">     223 </span>                :            :         }
<span class="lineNum">     224 </span>                :<span class="lineNoCov">          0 :         big_port = atoi(ch + 1);</span>
<span class="lineNum">     225 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (big_port &lt; 1 || big_port &gt; 65535) {</span>
<span class="lineNum">     226 </span>                :<span class="lineNoCov">          0 :             return APR_EINVAL;</span>
<span class="lineNum">     227 </span>                :            :         }
<span class="lineNum">     228 </span>                :<span class="lineNoCov">          0 :         *port = big_port;</span>
<span class="lineNum">     229 </span>                :<span class="lineNoCov">          0 :         lastchar = ch - 1;</span>
<span class="lineNum">     230 </span>                :            :     }
<span class="lineNum">     231 </span>                :            : 
<span class="lineNum">     232 </span>                :            :     /* now handle the hostname */
<span class="lineNum">     233 </span>                :<span class="lineNoCov">          0 :     addrlen = lastchar - str + 1;</span>
<span class="lineNum">     234 </span>                :            : 
<span class="lineNum">     235 </span>                :            : /* XXX we don't really have to require APR_HAVE_IPV6 for this; 
<span class="lineNum">     236 </span>                :            :  * just pass char[] for ipaddr (so we don't depend on struct in6_addr)
<span class="lineNum">     237 </span>                :            :  * and always define APR_INET6 
<span class="lineNum">     238 </span>                :            :  */
<span class="lineNum">     239 </span>                :            : #if APR_HAVE_IPV6
<span class="lineNum">     240 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :     if (*str == '[') {</span>
<span class="lineNum">     241 </span>                :<span class="lineNoCov">          0 :         const char *end_bracket = memchr(str, ']', addrlen);</span>
<span class="lineNum">     242 </span>                :            :         struct in6_addr ipaddr;
<span class="lineNum">     243 </span>                :            :         const char *scope_delim;
<span class="lineNum">     244 </span>                :            : 
<span class="lineNum">     245 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (!end_bracket || end_bracket != lastchar) {</span>
<span class="lineNum">     246 </span>                :<span class="lineNoCov">          0 :             *port = 0;</span>
<span class="lineNum">     247 </span>                :<span class="lineNoCov">          0 :             return APR_EINVAL;</span>
<span class="lineNum">     248 </span>                :            :         }
<span class="lineNum">     249 </span>                :            : 
<span class="lineNum">     250 </span>                :            :         /* handle scope id; this is the only context where it is allowed */
<span class="lineNum">     251 </span>                :<span class="lineNoCov">          0 :         scope_delim = memchr(str, '%', addrlen);</span>
<span class="lineNum">     252 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (scope_delim) {</span>
<span class="lineNum">     253 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :             if (scope_delim == end_bracket - 1) { /* '%' without scope id */</span>
<span class="lineNum">     254 </span>                :<span class="lineNoCov">          0 :                 *port = 0;</span>
<span class="lineNum">     255 </span>                :<span class="lineNoCov">          0 :                 return APR_EINVAL;</span>
<span class="lineNum">     256 </span>                :            :             }
<span class="lineNum">     257 </span>                :<span class="lineNoCov">          0 :             addrlen = scope_delim - str - 1;</span>
<span class="lineNum">     258 </span>                :<span class="lineNoCov">          0 :             *scope_id = apr_palloc(p, end_bracket - scope_delim);</span>
<span class="lineNum">     259 </span>                :<span class="lineNoCov">          0 :             memcpy(*scope_id, scope_delim + 1, end_bracket - scope_delim - 1);</span>
<span class="lineNum">     260 </span>                :<span class="lineNoCov">          0 :             (*scope_id)[end_bracket - scope_delim - 1] = '\0';</span>
<span class="lineNum">     261 </span>                :            :         }
<span class="lineNum">     262 </span>                :            :         else {
<span class="lineNum">     263 </span>                :<span class="lineNoCov">          0 :             addrlen = addrlen - 2; /* minus 2 for '[' and ']' */</span>
<span class="lineNum">     264 </span>                :            :         }
<span class="lineNum">     265 </span>                :            : 
<span class="lineNum">     266 </span>                :<span class="lineNoCov">          0 :         *addr = apr_palloc(p, addrlen + 1);</span>
<span class="lineNum">     267 </span>                :<span class="lineNoCov">          0 :         memcpy(*addr,</span>
<span class="lineNum">     268 </span>                :            :                str + 1,
<span class="lineNum">     269 </span>                :            :                addrlen);
<span class="lineNum">     270 </span>                :<span class="lineNoCov">          0 :         (*addr)[addrlen] = '\0';</span>
<span class="lineNum">     271 </span>        [<span class="branchNoExec" title="Branch 1 was not executed"> # </span><span class="branchNoExec" title="Branch 2 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (apr_inet_pton(AF_INET6, *addr, &amp;ipaddr) != 1) {</span>
<span class="lineNum">     272 </span>                :<span class="lineNoCov">          0 :             *addr = NULL;</span>
<span class="lineNum">     273 </span>                :<span class="lineNoCov">          0 :             *scope_id = NULL;</span>
<span class="lineNum">     274 </span>                :<span class="lineNoCov">          0 :             *port = 0;</span>
<span class="lineNum">     275 </span>                :<span class="lineNoCov">          0 :             return APR_EINVAL;</span>
<span class="lineNum">     276 </span>                :            :         }
<span class="lineNum">     277 </span>                :            :     }
<span class="lineNum">     278 </span>                :            :     else 
<span class="lineNum">     279 </span>                :            : #endif
<span class="lineNum">     280 </span>                :            :     {
<span class="lineNum">     281 </span>                :            :         /* XXX If '%' is not a valid char in a DNS name, we *could* check 
<span class="lineNum">     282 </span>                :            :          *     for bogus scope ids first.
<span class="lineNum">     283 </span>                :            :          */
<span class="lineNum">     284 </span>                :<span class="lineNoCov">          0 :         *addr = apr_palloc(p, addrlen + 1);</span>
<span class="lineNum">     285 </span>                :<span class="lineNoCov">          0 :         memcpy(*addr, str, addrlen);</span>
<span class="lineNum">     286 </span>                :<span class="lineNoCov">          0 :         (*addr)[addrlen] = '\0';</span>
<span class="lineNum">     287 </span>                :            :     }
<span class="lineNum">     288 </span>                :<span class="lineNoCov">          0 :     return APR_SUCCESS;</span>
<span class="lineNum">     289 </span>                :            : }
<span class="lineNum">     290 </span>                :            : 
<span class="lineNum">     291 </span>                :            : #if defined(HAVE_GETADDRINFO)
<span class="lineNum">     292 </span>                :            : 
<span class="lineNum">     293 </span>                :            : static apr_status_t call_resolver(apr_sockaddr_t **sa,
<span class="lineNum">     294 </span>                :            :                                   const char *hostname, apr_int32_t family,
<a name="295"><span class="lineNum">     295 </span>                :            :                                   apr_port_t port, apr_int32_t flags, </a>
<span class="lineNum">     296 </span>                :            :                                   apr_pool_t *p)
<span class="lineNum">     297 </span>                :<span class="lineCov">        252 : {</span>
<span class="lineNum">     298 </span>                :            :     struct addrinfo hints, *ai, *ai_list;
<span class="lineNum">     299 </span>                :            :     apr_sockaddr_t *prev_sa;
<span class="lineNum">     300 </span>                :            :     int error;
<span class="lineNum">     301 </span>                :<span class="lineCov">        252 :     char *servname = NULL; </span>
<span class="lineNum">     302 </span>                :            : 
<span class="lineNum">     303 </span>                :            :     memset(&amp;hints, 0, sizeof(hints));
<span class="lineNum">     304 </span>                :<span class="lineCov">        252 :     hints.ai_family = family;</span>
<span class="lineNum">     305 </span>                :<span class="lineCov">        252 :     hints.ai_socktype = SOCK_STREAM;</span>
<span class="lineNum">     306 </span>                :            : #ifdef HAVE_GAI_ADDRCONFIG
<span class="lineNum">     307 </span>        [<span class="branchCov" title="Branch 0 was taken 114 times"> + </span><span class="branchCov" title="Branch 1 was taken 138 times"> + </span>]:<span class="lineCov">        252 :     if (family == APR_UNSPEC) {</span>
<span class="lineNum">     308 </span>                :            :         /* By default, only look up addresses using address types for
<span class="lineNum">     309 </span>                :            :          * which a local interface is configured, i.e. no IPv6 if no
<span class="lineNum">     310 </span>                :            :          * IPv6 interfaces configured. */
<span class="lineNum">     311 </span>                :<span class="lineCov">        114 :         hints.ai_flags = AI_ADDRCONFIG;</span>
<span class="lineNum">     312 </span>                :            :     }
<span class="lineNum">     313 </span>                :            : #endif
<span class="lineNum">     314 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 250 times"> + </span>]:<span class="lineCov">        252 :     if(hostname == NULL) {</span>
<span class="lineNum">     315 </span>                :            : #ifdef AI_PASSIVE 
<span class="lineNum">     316 </span>                :            :         /* If hostname is NULL, assume we are trying to bind to all
<span class="lineNum">     317 </span>                :            :          * interfaces. */
<span class="lineNum">     318 </span>                :<span class="lineCov">          2 :         hints.ai_flags |= AI_PASSIVE;</span>
<span class="lineNum">     319 </span>                :            : #endif
<span class="lineNum">     320 </span>                :            :         /* getaddrinfo according to RFC 2553 must have either hostname
<span class="lineNum">     321 </span>                :            :          * or servname non-NULL.
<span class="lineNum">     322 </span>                :            :          */
<span class="lineNum">     323 </span>                :            : #ifdef OSF1
<span class="lineNum">     324 </span>                :            :         /* The Tru64 5.0 getaddrinfo() can only resolve services given
<span class="lineNum">     325 </span>                :            :          * by the name listed in /etc/services; a numeric or unknown
<span class="lineNum">     326 </span>                :            :          * servname gets an EAI_SERVICE error.  So just resolve the
<span class="lineNum">     327 </span>                :            :          * appropriate anyaddr and fill in the port later. */
<span class="lineNum">     328 </span>                :            :         hostname = family == AF_INET6 ? &quot;::&quot; : &quot;0.0.0.0&quot;;
<span class="lineNum">     329 </span>                :            :         servname = NULL;
<span class="lineNum">     330 </span>                :            : #ifdef AI_NUMERICHOST
<span class="lineNum">     331 </span>                :            :         hints.ai_flags |= AI_NUMERICHOST;
<span class="lineNum">     332 </span>                :            : #endif
<span class="lineNum">     333 </span>                :            : #else
<span class="lineNum">     334 </span>                :            : #ifdef _AIX
<span class="lineNum">     335 </span>                :            :         /* But current AIX getaddrinfo() doesn't like servname = &quot;0&quot;;
<span class="lineNum">     336 </span>                :            :          * the &quot;1&quot; won't hurt since we use the port parameter to fill
<span class="lineNum">     337 </span>                :            :          * in the returned socket addresses later
<span class="lineNum">     338 </span>                :            :          */
<span class="lineNum">     339 </span>                :            :         if (!port) {
<span class="lineNum">     340 </span>                :            :             servname = &quot;1&quot;;
<span class="lineNum">     341 </span>                :            :         }
<span class="lineNum">     342 </span>                :            :         else
<span class="lineNum">     343 </span>                :            : #endif /* _AIX */
<span class="lineNum">     344 </span>                :<span class="lineCov">          2 :         servname = apr_itoa(p, port);</span>
<span class="lineNum">     345 </span>                :            : #endif /* OSF1 */
<span class="lineNum">     346 </span>                :            :     }
<span class="lineNum">     347 </span>                :<span class="lineCov">        252 :     error = getaddrinfo(hostname, servname, &amp;hints, &amp;ai_list);</span>
<span class="lineNum">     348 </span>                :            : #ifdef HAVE_GAI_ADDRCONFIG
<span class="lineNum">     349 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 252 times"> + </span>]:<span class="lineCov">        252 :     if (error == EAI_BADFLAGS &amp;&amp; family == APR_UNSPEC) {</span>
<span class="lineNum">     350 </span>                :            :         /* Retry with no flags if AI_ADDRCONFIG was rejected. */
<span class="lineNum">     351 </span>                :<span class="lineNoCov">          0 :         hints.ai_flags = 0;</span>
<span class="lineNum">     352 </span>                :<span class="lineNoCov">          0 :         error = getaddrinfo(hostname, servname, &amp;hints, &amp;ai_list);</span>
<span class="lineNum">     353 </span>                :            :     }
<span class="lineNum">     354 </span>                :            : #endif
<span class="lineNum">     355 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 252 times"> + </span>]:<span class="lineCov">        252 :     if (error) {</span>
<span class="lineNum">     356 </span>                :            : #ifndef WIN32
<span class="lineNum">     357 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (error == EAI_SYSTEM) {</span>
<span class="lineNum">     358 </span>                :<span class="lineNoCov">          0 :             return errno;</span>
<span class="lineNum">     359 </span>                :            :         }
<span class="lineNum">     360 </span>                :            :         else 
<span class="lineNum">     361 </span>                :            : #endif
<span class="lineNum">     362 </span>                :            :         {
<span class="lineNum">     363 </span>                :            :             /* issues with representing this with APR's error scheme:
<span class="lineNum">     364 </span>                :            :              * glibc uses negative values for these numbers, perhaps so 
<span class="lineNum">     365 </span>                :            :              * they don't conflict with h_errno values...  Tru64 uses 
<span class="lineNum">     366 </span>                :            :              * positive values which conflict with h_errno values
<span class="lineNum">     367 </span>                :            :              */
<span class="lineNum">     368 </span>                :            : #if defined(NEGATIVE_EAI)
<span class="lineNum">     369 </span>                :<span class="lineNoCov">          0 :             error = -error;</span>
<span class="lineNum">     370 </span>                :            : #endif
<span class="lineNum">     371 </span>                :<span class="lineNoCov">          0 :             return error + APR_OS_START_EAIERR;</span>
<span class="lineNum">     372 </span>                :            :         }
<span class="lineNum">     373 </span>                :            :     }
<span class="lineNum">     374 </span>                :            : 
<span class="lineNum">     375 </span>                :<span class="lineCov">        252 :     prev_sa = NULL;</span>
<span class="lineNum">     376 </span>                :<span class="lineCov">        252 :     ai = ai_list;</span>
<span class="lineNum">     377 </span>        [<span class="branchCov" title="Branch 0 was taken 252 times"> + </span><span class="branchCov" title="Branch 1 was taken 252 times"> + </span>]:<span class="lineCov">        504 :     while (ai) { /* while more addresses to report */</span>
<span class="lineNum">     378 </span>                :            :         apr_sockaddr_t *new_sa;
<span class="lineNum">     379 </span>                :            : 
<span class="lineNum">     380 </span>                :            :         /* Ignore anything bogus: getaddrinfo in some old versions of
<span class="lineNum">     381 </span>                :            :          * glibc will return AF_UNIX entries for APR_UNSPEC+AI_PASSIVE
<span class="lineNum">     382 </span>                :            :          * lookups. */
<span class="lineNum">     383 </span>                :            : #if APR_HAVE_IPV6
<span class="lineNum">     384 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 252 times"> + </span>]:<span class="lineCov">        252 :         if (ai-&gt;ai_family != AF_INET &amp;&amp; ai-&gt;ai_family != AF_INET6) {</span>
<span class="lineNum">     385 </span>                :            : #else
<span class="lineNum">     386 </span>                :            :         if (ai-&gt;ai_family != AF_INET) {
<span class="lineNum">     387 </span>                :            : #endif
<span class="lineNum">     388 </span>                :<span class="lineNoCov">          0 :             ai = ai-&gt;ai_next;</span>
<span class="lineNum">     389 </span>                :<span class="lineNoCov">          0 :             continue;</span>
<span class="lineNum">     390 </span>                :            :         }
<span class="lineNum">     391 </span>                :            : 
<span class="lineNum">     392 </span>                :<span class="lineCov">        252 :         new_sa = apr_pcalloc(p, sizeof(apr_sockaddr_t));</span>
<span class="lineNum">     393 </span>                :            : 
<span class="lineNum">     394 </span>                :<span class="lineCov">        252 :         new_sa-&gt;pool = p;</span>
<span class="lineNum">     395 </span>                :<span class="lineCov">        252 :         memcpy(&amp;new_sa-&gt;sa, ai-&gt;ai_addr, ai-&gt;ai_addrlen);</span>
<span class="lineNum">     396 </span>                :<span class="lineCov">        252 :         apr_sockaddr_vars_set(new_sa, ai-&gt;ai_family, port);</span>
<span class="lineNum">     397 </span>                :            : 
<span class="lineNum">     398 </span>        [<span class="branchCov" title="Branch 0 was taken 252 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">        252 :         if (!prev_sa) { /* first element in new list */</span>
<span class="lineNum">     399 </span>        [<span class="branchCov" title="Branch 0 was taken 250 times"> + </span><span class="branchCov" title="Branch 1 was taken 2 times"> + </span>]:<span class="lineCov">        252 :             if (hostname) {</span>
<span class="lineNum">     400 </span>                :<span class="lineCov">        250 :                 new_sa-&gt;hostname = apr_pstrdup(p, hostname);</span>
<span class="lineNum">     401 </span>                :            :             }
<span class="lineNum">     402 </span>                :<span class="lineCov">        252 :             *sa = new_sa;</span>
<span class="lineNum">     403 </span>                :            :         }
<span class="lineNum">     404 </span>                :            :         else {
<span class="lineNum">     405 </span>                :<span class="lineNoCov">          0 :             new_sa-&gt;hostname = prev_sa-&gt;hostname;</span>
<span class="lineNum">     406 </span>                :<span class="lineNoCov">          0 :             prev_sa-&gt;next = new_sa;</span>
<span class="lineNum">     407 </span>                :            :         }
<span class="lineNum">     408 </span>                :            : 
<span class="lineNum">     409 </span>                :<span class="lineCov">        252 :         prev_sa = new_sa;</span>
<span class="lineNum">     410 </span>                :<span class="lineCov">        252 :         ai = ai-&gt;ai_next;</span>
<span class="lineNum">     411 </span>                :            :     }
<span class="lineNum">     412 </span>                :<span class="lineCov">        252 :     freeaddrinfo(ai_list);</span>
<span class="lineNum">     413 </span>                :<span class="lineCov">        252 :     return APR_SUCCESS;</span>
<span class="lineNum">     414 </span>                :            : }
<span class="lineNum">     415 </span>                :            : 
<span class="lineNum">     416 </span>                :            : static apr_status_t find_addresses(apr_sockaddr_t **sa, 
<span class="lineNum">     417 </span>                :            :                                    const char *hostname, apr_int32_t family,
<span class="lineNum">     418 </span>                :            :                                    apr_port_t port, apr_int32_t flags, 
<a name="419"><span class="lineNum">     419 </span>                :            :                                    apr_pool_t *p)</a>
<span class="lineNum">     420 </span>                :            : {
<span class="lineNum">     421 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 252 times"> + </span>]:<span class="lineCov">        252 :     if (flags &amp; APR_IPV4_ADDR_OK) {</span>
<span class="lineNum">     422 </span>                :<span class="lineNoCov">          0 :         apr_status_t error = call_resolver(sa, hostname, AF_INET, port, flags, p);</span>
<span class="lineNum">     423 </span>                :            : 
<span class="lineNum">     424 </span>                :            : #if APR_HAVE_IPV6
<span class="lineNum">     425 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (error) {</span>
<span class="lineNum">     426 </span>                :<span class="lineNoCov">          0 :             family = AF_INET6; /* try again */</span>
<span class="lineNum">     427 </span>                :            :         }
<span class="lineNum">     428 </span>                :            :         else
<span class="lineNum">     429 </span>                :            : #endif
<span class="lineNum">     430 </span>                :<span class="lineNoCov">          0 :         return error;</span>
<span class="lineNum">     431 </span>                :            :     }
<span class="lineNum">     432 </span>                :            : #if APR_HAVE_IPV6
<span class="lineNum">     433 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 252 times"> + </span>]:<span class="lineCov">        252 :     else if (flags &amp; APR_IPV6_ADDR_OK) {</span>
<span class="lineNum">     434 </span>                :<span class="lineNoCov">          0 :         apr_status_t error = call_resolver(sa, hostname, AF_INET6, port, flags, p);</span>
<span class="lineNum">     435 </span>                :            : 
<span class="lineNum">     436 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (error) {</span>
<span class="lineNum">     437 </span>                :<span class="lineNoCov">          0 :             family = AF_INET; /* try again */</span>
<span class="lineNum">     438 </span>                :            :         }
<span class="lineNum">     439 </span>                :            :         else {
<span class="lineNum">     440 </span>                :<span class="lineNoCov">          0 :             return APR_SUCCESS;</span>
<span class="lineNum">     441 </span>                :            :         }
<span class="lineNum">     442 </span>                :            :     }
<span class="lineNum">     443 </span>                :            : #endif
<span class="lineNum">     444 </span>                :            : 
<span class="lineNum">     445 </span>                :<span class="lineCov">        252 :     return call_resolver(sa, hostname, family, port, flags, p);</span>
<span class="lineNum">     446 </span>                :            : }
<span class="lineNum">     447 </span>                :            : 
<span class="lineNum">     448 </span>                :            : #else /* end of HAVE_GETADDRINFO code */
<span class="lineNum">     449 </span>                :            : 
<span class="lineNum">     450 </span>                :            : static apr_status_t find_addresses(apr_sockaddr_t **sa, 
<span class="lineNum">     451 </span>                :            :                                    const char *hostname, apr_int32_t family,
<span class="lineNum">     452 </span>                :            :                                    apr_port_t port, apr_int32_t flags, 
<span class="lineNum">     453 </span>                :            :                                    apr_pool_t *p)
<span class="lineNum">     454 </span>                :            : {
<span class="lineNum">     455 </span>                :            :     struct hostent *hp;
<span class="lineNum">     456 </span>                :            :     apr_sockaddr_t *prev_sa;
<span class="lineNum">     457 </span>                :            :     int curaddr;
<span class="lineNum">     458 </span>                :            : #if APR_HAS_THREADS &amp;&amp; !defined(GETHOSTBYNAME_IS_THREAD_SAFE) &amp;&amp; \
<span class="lineNum">     459 </span>                :            :     defined(HAVE_GETHOSTBYNAME_R) &amp;&amp; !defined(BEOS)
<span class="lineNum">     460 </span>                :            : #ifdef GETHOSTBYNAME_R_HOSTENT_DATA
<span class="lineNum">     461 </span>                :            :     struct hostent_data hd;
<span class="lineNum">     462 </span>                :            : #else
<span class="lineNum">     463 </span>                :            :     /* If you see ERANGE, that means GETHOSBYNAME_BUFLEN needs to be
<span class="lineNum">     464 </span>                :            :      * bumped. */
<span class="lineNum">     465 </span>                :            :     char tmp[GETHOSTBYNAME_BUFLEN];
<span class="lineNum">     466 </span>                :            : #endif
<span class="lineNum">     467 </span>                :            :     int hosterror;
<span class="lineNum">     468 </span>                :            : #endif
<span class="lineNum">     469 </span>                :            :     struct hostent hs;
<span class="lineNum">     470 </span>                :            :     struct in_addr ipaddr;
<span class="lineNum">     471 </span>                :            :     char *addr_list[2];
<span class="lineNum">     472 </span>                :            :     const char *orig_hostname = hostname;
<span class="lineNum">     473 </span>                :            : 
<span class="lineNum">     474 </span>                :            :     if (hostname == NULL) {
<span class="lineNum">     475 </span>                :            :         /* if we are given a NULL hostname, assume '0.0.0.0' */
<span class="lineNum">     476 </span>                :            :         hostname = &quot;0.0.0.0&quot;;
<span class="lineNum">     477 </span>                :            :     }
<span class="lineNum">     478 </span>                :            : 
<span class="lineNum">     479 </span>                :            :     if (*hostname &gt;= '0' &amp;&amp; *hostname &lt;= '9' &amp;&amp;
<span class="lineNum">     480 </span>                :            :         strspn(hostname, &quot;0123456789.&quot;) == strlen(hostname)) {
<span class="lineNum">     481 </span>                :            : 
<span class="lineNum">     482 </span>                :            :         ipaddr.s_addr = inet_addr(hostname);
<span class="lineNum">     483 </span>                :            :         addr_list[0] = (char *)&amp;ipaddr;
<span class="lineNum">     484 </span>                :            :         addr_list[1] = NULL; /* just one IP in list */
<span class="lineNum">     485 </span>                :            :         hs.h_addr_list = (char **)addr_list;
<span class="lineNum">     486 </span>                :            :         hp = &amp;hs;
<span class="lineNum">     487 </span>                :            :     }
<span class="lineNum">     488 </span>                :            :     else {
<span class="lineNum">     489 </span>                :            : #if APR_HAS_THREADS &amp;&amp; !defined(GETHOSTBYNAME_IS_THREAD_SAFE) &amp;&amp; \
<span class="lineNum">     490 </span>                :            :     defined(HAVE_GETHOSTBYNAME_R) &amp;&amp; !defined(BEOS)
<span class="lineNum">     491 </span>                :            : #if defined(GETHOSTBYNAME_R_HOSTENT_DATA)
<span class="lineNum">     492 </span>                :            :         /* AIX, HP/UX, D/UX et alia */
<span class="lineNum">     493 </span>                :            :         gethostbyname_r(hostname, &amp;hs, &amp;hd);
<span class="lineNum">     494 </span>                :            :         hp = &amp;hs;
<span class="lineNum">     495 </span>                :            : #else
<span class="lineNum">     496 </span>                :            : #if defined(GETHOSTBYNAME_R_GLIBC2)
<span class="lineNum">     497 </span>                :            :         /* Linux glibc2+ */
<span class="lineNum">     498 </span>                :            :         gethostbyname_r(hostname, &amp;hs, tmp, GETHOSTBYNAME_BUFLEN - 1, 
<span class="lineNum">     499 </span>                :            :                         &amp;hp, &amp;hosterror);
<span class="lineNum">     500 </span>                :            : #else
<span class="lineNum">     501 </span>                :            :         /* Solaris, Irix et alia */
<span class="lineNum">     502 </span>                :            :         hp = gethostbyname_r(hostname, &amp;hs, tmp, GETHOSTBYNAME_BUFLEN - 1,
<span class="lineNum">     503 </span>                :            :                              &amp;hosterror);
<span class="lineNum">     504 </span>                :            : #endif /* !defined(GETHOSTBYNAME_R_GLIBC2) */
<span class="lineNum">     505 </span>                :            :         if (!hp) {
<span class="lineNum">     506 </span>                :            :             return (hosterror + APR_OS_START_SYSERR);
<span class="lineNum">     507 </span>                :            :         }
<span class="lineNum">     508 </span>                :            : #endif /* !defined(GETHOSTBYNAME_R_HOSTENT_DATA) */
<span class="lineNum">     509 </span>                :            : #else
<span class="lineNum">     510 </span>                :            :         hp = gethostbyname(hostname);
<span class="lineNum">     511 </span>                :            : #endif
<span class="lineNum">     512 </span>                :            : 
<span class="lineNum">     513 </span>                :            :         if (!hp) {
<span class="lineNum">     514 </span>                :            : #ifdef WIN32
<span class="lineNum">     515 </span>                :            :             return apr_get_netos_error();
<span class="lineNum">     516 </span>                :            : #else
<span class="lineNum">     517 </span>                :            :             return (h_errno + APR_OS_START_SYSERR);
<span class="lineNum">     518 </span>                :            : #endif
<span class="lineNum">     519 </span>                :            :         }
<span class="lineNum">     520 </span>                :            :     }
<span class="lineNum">     521 </span>                :            : 
<span class="lineNum">     522 </span>                :            :     prev_sa = NULL;
<span class="lineNum">     523 </span>                :            :     curaddr = 0;
<span class="lineNum">     524 </span>                :            :     while (hp-&gt;h_addr_list[curaddr]) {
<span class="lineNum">     525 </span>                :            :         apr_sockaddr_t *new_sa = apr_pcalloc(p, sizeof(apr_sockaddr_t));
<span class="lineNum">     526 </span>                :            : 
<span class="lineNum">     527 </span>                :            :         new_sa-&gt;pool = p;
<span class="lineNum">     528 </span>                :            :         new_sa-&gt;sa.sin.sin_addr = *(struct in_addr *)hp-&gt;h_addr_list[curaddr];
<span class="lineNum">     529 </span>                :            :         apr_sockaddr_vars_set(new_sa, AF_INET, port);
<span class="lineNum">     530 </span>                :            : 
<span class="lineNum">     531 </span>                :            :         if (!prev_sa) { /* first element in new list */
<span class="lineNum">     532 </span>                :            :             if (orig_hostname) {
<span class="lineNum">     533 </span>                :            :                 new_sa-&gt;hostname = apr_pstrdup(p, orig_hostname);
<span class="lineNum">     534 </span>                :            :             }
<span class="lineNum">     535 </span>                :            :             *sa = new_sa;
<span class="lineNum">     536 </span>                :            :         }
<span class="lineNum">     537 </span>                :            :         else {
<span class="lineNum">     538 </span>                :            :             new_sa-&gt;hostname = prev_sa-&gt;hostname;
<span class="lineNum">     539 </span>                :            :             prev_sa-&gt;next = new_sa;
<span class="lineNum">     540 </span>                :            :         }
<span class="lineNum">     541 </span>                :            : 
<span class="lineNum">     542 </span>                :            :         prev_sa = new_sa;
<span class="lineNum">     543 </span>                :            :         ++curaddr;
<span class="lineNum">     544 </span>                :            :     }
<span class="lineNum">     545 </span>                :            : 
<span class="lineNum">     546 </span>                :            :     return APR_SUCCESS;
<span class="lineNum">     547 </span>                :            : }
<span class="lineNum">     548 </span>                :            : 
<span class="lineNum">     549 </span>                :            : #endif /* end of !HAVE_GETADDRINFO code */
<span class="lineNum">     550 </span>                :            : 
<span class="lineNum">     551 </span>                :            : APR_DECLARE(apr_status_t) apr_sockaddr_info_get(apr_sockaddr_t **sa,
<span class="lineNum">     552 </span>                :            :                                                 const char *hostname, 
<span class="lineNum">     553 </span>                :            :                                                 apr_int32_t family, apr_port_t port,
<span class="lineNum">     554 </span>                :            :                                                 apr_int32_t flags, apr_pool_t *p)
<span class="lineNum">     555 </span>                :<span class="lineCov">        252 : {</span>
<span class="lineNum">     556 </span>                :            :     apr_int32_t masked;
<span class="lineNum">     557 </span>                :<span class="lineCov">        252 :     *sa = NULL;</span>
<span class="lineNum">     558 </span>                :            : 
<span class="lineNum">     559 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 252 times"> + </span>]:<span class="lineCov">        252 :     if ((masked = flags &amp; (APR_IPV4_ADDR_OK | APR_IPV6_ADDR_OK))) {</span>
<span class="lineNum">     560 </span>[<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>][<span class="branchNoExec" title="Branch 2 was not executed"> # </span><span class="branchNoExec" title="Branch 3 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (!hostname ||</span>
<span class="lineNum">     561 </span>                :            :             family != APR_UNSPEC ||
<span class="lineNum">     562 </span>                :            :             masked == (APR_IPV4_ADDR_OK | APR_IPV6_ADDR_OK)) {
<span class="lineNum">     563 </span>                :<span class="lineNoCov">          0 :             return APR_EINVAL;</span>
<span class="lineNum">     564 </span>                :            :         }
<span class="lineNum">     565 </span>                :            : #if !APR_HAVE_IPV6
<span class="lineNum">     566 </span>                :            :         if (flags &amp; APR_IPV6_ADDR_OK) {
<span class="lineNum">     567 </span>                :            :             return APR_ENOTIMPL;
<span class="lineNum">     568 </span>                :            :         }
<span class="lineNum">     569 </span>                :            : #endif
<span class="lineNum">     570 </span>                :            :     }
<span class="lineNum">     571 </span>                :            : #if !APR_HAVE_IPV6
<span class="lineNum">     572 </span>                :            :     /* What may happen is that APR is not IPv6-enabled, but we're still
<span class="lineNum">     573 </span>                :            :      * going to call getaddrinfo(), so we have to tell the OS we only
<span class="lineNum">     574 </span>                :            :      * want IPv4 addresses back since we won't know what to do with
<span class="lineNum">     575 </span>                :            :      * IPv6 addresses.
<span class="lineNum">     576 </span>                :            :      */
<span class="lineNum">     577 </span>                :            :     if (family == APR_UNSPEC) {
<span class="lineNum">     578 </span>                :            :         family = APR_INET;
<span class="lineNum">     579 </span>                :            :     }
<span class="lineNum">     580 </span>                :            : #endif
<span class="lineNum">     581 </span>                :            : 
<span class="lineNum">     582 </span>                :<span class="lineCov">        252 :     return find_addresses(sa, hostname, family, port, flags, p);</span>
<span class="lineNum">     583 </span>                :            : }
<span class="lineNum">     584 </span>                :            : 
<span class="lineNum">     585 </span>                :            : APR_DECLARE(apr_status_t) apr_getnameinfo(char **hostname,
<a name="586"><span class="lineNum">     586 </span>                :            :                                           apr_sockaddr_t *sockaddr,</a>
<span class="lineNum">     587 </span>                :            :                                           apr_int32_t flags)
<span class="lineNum">     588 </span>                :<span class="lineNoCov">          0 : {</span>
<span class="lineNum">     589 </span>                :            : #if defined(HAVE_GETNAMEINFO)
<span class="lineNum">     590 </span>                :            :     int rc;
<span class="lineNum">     591 </span>                :            : #if defined(NI_MAXHOST)
<span class="lineNum">     592 </span>                :            :     char tmphostname[NI_MAXHOST];
<span class="lineNum">     593 </span>                :            : #else
<span class="lineNum">     594 </span>                :            :     char tmphostname[256];
<span class="lineNum">     595 </span>                :            : #endif
<span class="lineNum">     596 </span>                :            : 
<span class="lineNum">     597 </span>                :            :     /* don't know if it is portable for getnameinfo() to set h_errno;
<span class="lineNum">     598 </span>                :            :      * clear it then see if it was set */
<span class="lineNum">     599 </span>                :<span class="lineNoCov">          0 :     SET_H_ERRNO(0);</span>
<span class="lineNum">     600 </span>                :            : 
<span class="lineNum">     601 </span>                :            :     /* default flags are NI_NAMREQD; otherwise, getnameinfo() will return
<span class="lineNum">     602 </span>                :            :      * a numeric address string if it fails to resolve the host name;
<span class="lineNum">     603 </span>                :            :      * that is *not* what we want here
<span class="lineNum">     604 </span>                :            :      *
<span class="lineNum">     605 </span>                :            :      * For IPv4-mapped IPv6 addresses, drop down to IPv4 before calling
<span class="lineNum">     606 </span>                :            :      * getnameinfo() to avoid getnameinfo bugs (MacOS X, glibc).
<span class="lineNum">     607 </span>                :            :      */
<span class="lineNum">     608 </span>                :            : #if APR_HAVE_IPV6
<span class="lineNum">     609 </span>[<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>][<span class="branchNoExec" title="Branch 2 was not executed"> # </span><span class="branchNoExec" title="Branch 3 was not executed"> # </span>]:<span class="lineNoCov">          0 :     if (sockaddr-&gt;family == AF_INET6 &amp;&amp;</span>
<span class="lineNum">         </span>[<span class="branchNoExec" title="Branch 4 was not executed"> # </span><span class="branchNoExec" title="Branch 5 was not executed"> # </span>][<span class="branchNoExec" title="Branch 6 was not executed"> # </span><span class="branchNoExec" title="Branch 7 was not executed"> # </span>]
<span class="lineNum">     610 </span>        [<span class="branchNoExec" title="Branch 1 was not executed"> # </span><span class="branchNoExec" title="Branch 2 was not executed"> # </span>]:<span class="lineNoCov">          0 :         IN6_IS_ADDR_V4MAPPED(&amp;sockaddr-&gt;sa.sin6.sin6_addr)) {</span>
<span class="lineNum">     611 </span>                :            :         struct sockaddr_in tmpsa;
<span class="lineNum">     612 </span>                :<span class="lineNoCov">          0 :         tmpsa.sin_family = AF_INET;</span>
<span class="lineNum">     613 </span>                :<span class="lineNoCov">          0 :         tmpsa.sin_port = 0;</span>
<span class="lineNum">     614 </span>                :<span class="lineNoCov">          0 :         tmpsa.sin_addr.s_addr = ((apr_uint32_t *)sockaddr-&gt;ipaddr_ptr)[3];</span>
<span class="lineNum">     615 </span>                :            : #ifdef SIN6_LEN
<span class="lineNum">     616 </span>                :            :         tmpsa.sin_len = sizeof(tmpsa);
<span class="lineNum">     617 </span>                :            : #endif
<span class="lineNum">     618 </span>                :            : 
<span class="lineNum">     619 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         rc = getnameinfo((const struct sockaddr *)&amp;tmpsa, sizeof(tmpsa),</span>
<span class="lineNum">     620 </span>                :            :                          tmphostname, sizeof(tmphostname), NULL, 0,
<span class="lineNum">     621 </span>                :            :                          flags != 0 ? flags : NI_NAMEREQD);
<span class="lineNum">     622 </span>                :            :     }
<span class="lineNum">     623 </span>                :            :     else
<span class="lineNum">     624 </span>                :            : #endif
<span class="lineNum">     625 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :     rc = getnameinfo((const struct sockaddr *)&amp;sockaddr-&gt;sa, sockaddr-&gt;salen,</span>
<span class="lineNum">     626 </span>                :            :                      tmphostname, sizeof(tmphostname), NULL, 0,
<span class="lineNum">     627 </span>                :            :                      flags != 0 ? flags : NI_NAMEREQD);
<span class="lineNum">     628 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :     if (rc != 0) {</span>
<span class="lineNum">     629 </span>                :<span class="lineNoCov">          0 :         *hostname = NULL;</span>
<span class="lineNum">     630 </span>                :            : 
<span class="lineNum">     631 </span>                :            : #ifndef WIN32
<span class="lineNum">     632 </span>                :            :         /* something went wrong. Look at the EAI_ error code */
<span class="lineNum">     633 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (rc == EAI_SYSTEM) {</span>
<span class="lineNum">     634 </span>                :            :             /* EAI_SYSTEM      System error returned in errno. */
<span class="lineNum">     635 </span>                :            :             /* IMHO, Implementations that set h_errno a simply broken. */
<span class="lineNum">     636 </span>        [<span class="branchNoExec" title="Branch 1 was not executed"> # </span><span class="branchNoExec" title="Branch 2 was not executed"> # </span>]:<span class="lineNoCov">          0 :             if (h_errno) { /* for broken implementations which set h_errno */</span>
<span class="lineNum">     637 </span>                :<span class="lineNoCov">          0 :                 return h_errno + APR_OS_START_SYSERR;</span>
<span class="lineNum">     638 </span>                :            :             }
<span class="lineNum">     639 </span>                :            :             else { /* &quot;normal&quot; case */
<span class="lineNum">     640 </span>                :<span class="lineNoCov">          0 :                 return errno + APR_OS_START_SYSERR;</span>
<span class="lineNum">     641 </span>                :            :             }
<span class="lineNum">     642 </span>                :            :         }
<span class="lineNum">     643 </span>                :            :         else 
<span class="lineNum">     644 </span>                :            : #endif
<span class="lineNum">     645 </span>                :            :         {
<span class="lineNum">     646 </span>                :            : #if defined(NEGATIVE_EAI)
<span class="lineNum">     647 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :             if (rc &lt; 0) rc = -rc;</span>
<span class="lineNum">     648 </span>                :            : #endif
<span class="lineNum">     649 </span>                :<span class="lineNoCov">          0 :             return rc + APR_OS_START_EAIERR; /* return the EAI_ error */</span>
<span class="lineNum">     650 </span>                :            :         }
<span class="lineNum">     651 </span>                :            :     }
<span class="lineNum">     652 </span>                :<span class="lineNoCov">          0 :     *hostname = sockaddr-&gt;hostname = apr_pstrdup(sockaddr-&gt;pool, </span>
<span class="lineNum">     653 </span>                :            :                                                  tmphostname);
<span class="lineNum">     654 </span>                :<span class="lineNoCov">          0 :     return APR_SUCCESS;</span>
<span class="lineNum">     655 </span>                :            : #else
<span class="lineNum">     656 </span>                :            : #if APR_HAS_THREADS &amp;&amp; !defined(GETHOSTBYADDR_IS_THREAD_SAFE) &amp;&amp; \
<span class="lineNum">     657 </span>                :            :     defined(HAVE_GETHOSTBYADDR_R) &amp;&amp; !defined(BEOS)
<span class="lineNum">     658 </span>                :            : #ifdef GETHOSTBYNAME_R_HOSTENT_DATA
<span class="lineNum">     659 </span>                :            :     struct hostent_data hd;
<span class="lineNum">     660 </span>                :            : #else
<span class="lineNum">     661 </span>                :            :     char tmp[GETHOSTBYNAME_BUFLEN];
<span class="lineNum">     662 </span>                :            : #endif
<span class="lineNum">     663 </span>                :            :     int hosterror;
<span class="lineNum">     664 </span>                :            :     struct hostent hs, *hptr;
<span class="lineNum">     665 </span>                :            : 
<span class="lineNum">     666 </span>                :            : #if defined(GETHOSTBYNAME_R_HOSTENT_DATA)
<span class="lineNum">     667 </span>                :            :     /* AIX, HP/UX, D/UX et alia */
<span class="lineNum">     668 </span>                :            :     gethostbyaddr_r((char *)&amp;sockaddr-&gt;sa.sin.sin_addr, 
<span class="lineNum">     669 </span>                :            :                   sizeof(struct in_addr), AF_INET, &amp;hs, &amp;hd);
<span class="lineNum">     670 </span>                :            :     hptr = &amp;hs;
<span class="lineNum">     671 </span>                :            : #else
<span class="lineNum">     672 </span>                :            : #if defined(GETHOSTBYNAME_R_GLIBC2)
<span class="lineNum">     673 </span>                :            :     /* Linux glibc2+ */
<span class="lineNum">     674 </span>                :            :     gethostbyaddr_r((char *)&amp;sockaddr-&gt;sa.sin.sin_addr, 
<span class="lineNum">     675 </span>                :            :                     sizeof(struct in_addr), AF_INET,
<span class="lineNum">     676 </span>                :            :                     &amp;hs, tmp, GETHOSTBYNAME_BUFLEN - 1, &amp;hptr, &amp;hosterror);
<span class="lineNum">     677 </span>                :            : #else
<span class="lineNum">     678 </span>                :            :     /* Solaris, Irix et alia */
<span class="lineNum">     679 </span>                :            :     hptr = gethostbyaddr_r((char *)&amp;sockaddr-&gt;sa.sin.sin_addr, 
<span class="lineNum">     680 </span>                :            :                            sizeof(struct in_addr), AF_INET,
<span class="lineNum">     681 </span>                :            :                            &amp;hs, tmp, GETHOSTBYNAME_BUFLEN, &amp;hosterror);
<span class="lineNum">     682 </span>                :            : #endif /* !defined(GETHOSTBYNAME_R_GLIBC2) */
<span class="lineNum">     683 </span>                :            :     if (!hptr) {
<span class="lineNum">     684 </span>                :            :         *hostname = NULL;
<span class="lineNum">     685 </span>                :            :         return hosterror + APR_OS_START_SYSERR;
<span class="lineNum">     686 </span>                :            :     }
<span class="lineNum">     687 </span>                :            : #endif /* !defined(GETHOSTBYNAME_R_HOSTENT_DATA) */
<span class="lineNum">     688 </span>                :            : #else
<span class="lineNum">     689 </span>                :            :     struct hostent *hptr;
<span class="lineNum">     690 </span>                :            :     hptr = gethostbyaddr((char *)&amp;sockaddr-&gt;sa.sin.sin_addr, 
<span class="lineNum">     691 </span>                :            :                          sizeof(struct in_addr), AF_INET);
<span class="lineNum">     692 </span>                :            : #endif
<span class="lineNum">     693 </span>                :            : 
<span class="lineNum">     694 </span>                :            :     if (hptr) {
<span class="lineNum">     695 </span>                :            :         *hostname = sockaddr-&gt;hostname = apr_pstrdup(sockaddr-&gt;pool, hptr-&gt;h_name);
<span class="lineNum">     696 </span>                :            :         return APR_SUCCESS;
<span class="lineNum">     697 </span>                :            :     }
<span class="lineNum">     698 </span>                :            :     *hostname = NULL;
<span class="lineNum">     699 </span>                :            : #if defined(WIN32)
<span class="lineNum">     700 </span>                :            :     return apr_get_netos_error();
<span class="lineNum">     701 </span>                :            : #elif defined(OS2)
<span class="lineNum">     702 </span>                :            :     return h_errno;
<span class="lineNum">     703 </span>                :            : #else
<span class="lineNum">     704 </span>                :            :     return h_errno + APR_OS_START_SYSERR;
<span class="lineNum">     705 </span>                :            : #endif
<span class="lineNum">     706 </span>                :            : #endif
<span class="lineNum">     707 </span>                :            : }
<span class="lineNum">     708 </span>                :            : 
<a name="709"><span class="lineNum">     709 </span>                :            : APR_DECLARE(apr_status_t) apr_getservbyname(apr_sockaddr_t *sockaddr,</a>
<span class="lineNum">     710 </span>                :            :                                             const char *servname)
<span class="lineNum">     711 </span>                :<span class="lineCov">          3 : {</span>
<span class="lineNum">     712 </span>                :            : #if APR_HAS_THREADS &amp;&amp; !defined(GETSERVBYNAME_IS_THREAD_SAFE) &amp;&amp; \
<span class="lineNum">     713 </span>                :            :     defined(HAVE_GETSERVBYNAME_R) &amp;&amp; \
<span class="lineNum">     714 </span>                :            :     (defined(GETSERVBYNAME_R_GLIBC2) || defined(GETSERVBYNAME_R_SOLARIS) || \
<span class="lineNum">     715 </span>                :            :      defined(GETSERVBYNAME_R_OSF1))
<span class="lineNum">     716 </span>                :            :     struct servent se;
<span class="lineNum">     717 </span>                :            : #if defined(GETSERVBYNAME_R_OSF1)
<span class="lineNum">     718 </span>                :            :     struct servent_data sed;
<span class="lineNum">     719 </span>                :            : 
<span class="lineNum">     720 </span>                :            :     memset(&amp;sed, 0, sizeof(sed)); /* must zero fill before use */
<span class="lineNum">     721 </span>                :            : #else
<span class="lineNum">     722 </span>                :            : #if defined(GETSERVBYNAME_R_GLIBC2)
<span class="lineNum">     723 </span>                :            :     struct servent *res;
<span class="lineNum">     724 </span>                :            : #endif
<span class="lineNum">     725 </span>                :            :     char buf[1024];
<span class="lineNum">     726 </span>                :            : #endif
<span class="lineNum">     727 </span>                :            : #else
<span class="lineNum">     728 </span>                :            :     struct servent *se;
<span class="lineNum">     729 </span>                :            : #endif
<span class="lineNum">     730 </span>                :            : 
<span class="lineNum">     731 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>]:<span class="lineCov">          3 :     if (servname == NULL)</span>
<span class="lineNum">     732 </span>                :<span class="lineNoCov">          0 :         return APR_EINVAL;</span>
<span class="lineNum">     733 </span>                :            : 
<span class="lineNum">     734 </span>                :            : #if APR_HAS_THREADS &amp;&amp; !defined(GETSERVBYNAME_IS_THREAD_SAFE) &amp;&amp; \
<span class="lineNum">     735 </span>                :            :     defined(HAVE_GETSERVBYNAME_R) &amp;&amp; \
<span class="lineNum">     736 </span>                :            :     (defined(GETSERVBYNAME_R_GLIBC2) || defined(GETSERVBYNAME_R_SOLARIS) || \
<span class="lineNum">     737 </span>                :            :      defined(GETSERVBYNAME_R_OSF1))
<span class="lineNum">     738 </span>                :            : #if defined(GETSERVBYNAME_R_GLIBC2)
<span class="lineNum">     739 </span>[<span class="branchCov" title="Branch 1 was taken 3 times"> + </span><span class="branchNoCov" title="Branch 2 was not taken"> - </span>][<span class="branchCov" title="Branch 3 was taken 2 times"> + </span><span class="branchCov" title="Branch 4 was taken 1 time"> + </span>]:<span class="lineCov">          3 :     if (getservbyname_r(servname, NULL,</span>
<span class="lineNum">     740 </span>                :            :                         &amp;se, buf, sizeof(buf), &amp;res) == 0 &amp;&amp; res != NULL) {
<span class="lineNum">     741 </span>        [<span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchCov" title="Branch 2 was taken 2 times"> + </span>]:<span class="lineCov">          2 :         sockaddr-&gt;port = ntohs(res-&gt;s_port);</span>
<span class="lineNum">     742 </span>                :<span class="lineCov">          2 :         sockaddr-&gt;servname = apr_pstrdup(sockaddr-&gt;pool, servname);</span>
<span class="lineNum">     743 </span>                :<span class="lineCov">          2 :         sockaddr-&gt;sa.sin.sin_port = res-&gt;s_port;</span>
<span class="lineNum">     744 </span>                :<span class="lineCov">          2 :         return APR_SUCCESS;</span>
<span class="lineNum">     745 </span>                :            :     }
<span class="lineNum">     746 </span>                :            : #elif defined(GETSERVBYNAME_R_SOLARIS)
<span class="lineNum">     747 </span>                :            :     if (getservbyname_r(servname, NULL, &amp;se, buf, sizeof(buf)) != NULL) {
<span class="lineNum">     748 </span>                :            :         sockaddr-&gt;port = ntohs(se.s_port);
<span class="lineNum">     749 </span>                :            :         sockaddr-&gt;servname = apr_pstrdup(sockaddr-&gt;pool, servname);
<span class="lineNum">     750 </span>                :            :         sockaddr-&gt;sa.sin.sin_port = se.s_port;
<span class="lineNum">     751 </span>                :            :         return APR_SUCCESS;
<span class="lineNum">     752 </span>                :            :     }
<span class="lineNum">     753 </span>                :            : #elif defined(GETSERVBYNAME_R_OSF1)
<span class="lineNum">     754 </span>                :            :     if (getservbyname_r(servname, NULL, &amp;se, &amp;sed) == 0) {
<span class="lineNum">     755 </span>                :            :         sockaddr-&gt;port = ntohs(se.s_port);
<span class="lineNum">     756 </span>                :            :         sockaddr-&gt;servname = apr_pstrdup(sockaddr-&gt;pool, servname);
<span class="lineNum">     757 </span>                :            :         sockaddr-&gt;sa.sin.sin_port = se.s_port;
<span class="lineNum">     758 </span>                :            :         return APR_SUCCESS;
<span class="lineNum">     759 </span>                :            :     }
<span class="lineNum">     760 </span>                :            : #endif
<span class="lineNum">     761 </span>                :            : #else
<span class="lineNum">     762 </span>                :            :     if ((se = getservbyname(servname, NULL)) != NULL){
<span class="lineNum">     763 </span>                :            :         sockaddr-&gt;port = ntohs(se-&gt;s_port);
<span class="lineNum">     764 </span>                :            :         sockaddr-&gt;servname = apr_pstrdup(sockaddr-&gt;pool, servname);
<span class="lineNum">     765 </span>                :            :         sockaddr-&gt;sa.sin.sin_port = se-&gt;s_port;
<span class="lineNum">     766 </span>                :            :         return APR_SUCCESS;
<span class="lineNum">     767 </span>                :            :     }
<span class="lineNum">     768 </span>                :            : #endif
<span class="lineNum">     769 </span>                :<span class="lineCov">          3 :     return APR_ENOENT;</span>
<span class="lineNum">     770 </span>                :            : }
<span class="lineNum">     771 </span>                :            : 
<span class="lineNum">     772 </span>                :            : #define V4MAPPED_EQUAL(a,b)                                   \
<span class="lineNum">     773 </span>                :            : ((a)-&gt;sa.sin.sin_family == AF_INET &amp;&amp;                         \
<span class="lineNum">     774 </span>                :            :  (b)-&gt;sa.sin.sin_family == AF_INET6 &amp;&amp;                        \
<span class="lineNum">     775 </span>                :            :  IN6_IS_ADDR_V4MAPPED((struct in6_addr *)(b)-&gt;ipaddr_ptr) &amp;&amp;  \
<span class="lineNum">     776 </span>                :            :  !memcmp((a)-&gt;ipaddr_ptr,                                     \
<span class="lineNum">     777 </span>                :            :          &amp;((struct in6_addr *)(b)-&gt;ipaddr_ptr)-&gt;s6_addr[12],  \
<span class="lineNum">     778 </span>                :            :          (a)-&gt;ipaddr_len))
<span class="lineNum">     779 </span>                :            : 
<a name="780"><span class="lineNum">     780 </span>                :            : APR_DECLARE(int) apr_sockaddr_equal(const apr_sockaddr_t *addr1,</a>
<span class="lineNum">     781 </span>                :            :                                     const apr_sockaddr_t *addr2)
<span class="lineNum">     782 </span>                :<span class="lineNoCov">          0 : {</span>
<span class="lineNum">     783 </span>[<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>][<span class="branchNoExec" title="Branch 3 was not executed"> # </span><span class="branchNoExec" title="Branch 4 was not executed"> # </span>]:<span class="lineNoCov">          0 :     if (addr1-&gt;ipaddr_len == addr2-&gt;ipaddr_len &amp;&amp;</span>
<span class="lineNum">     784 </span>                :            :         !memcmp(addr1-&gt;ipaddr_ptr, addr2-&gt;ipaddr_ptr, addr1-&gt;ipaddr_len)) {
<span class="lineNum">     785 </span>                :<span class="lineNoCov">          0 :         return 1;</span>
<span class="lineNum">     786 </span>                :            :     }
<span class="lineNum">     787 </span>                :            : #if APR_HAVE_IPV6
<span class="lineNum">     788 </span>[<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>][<span class="branchNoExec" title="Branch 2 was not executed"> # </span><span class="branchNoExec" title="Branch 3 was not executed"> # </span>]:<span class="lineNoCov">          0 :     if (V4MAPPED_EQUAL(addr1, addr2)) {</span>
<span class="lineNum">         </span>[<span class="branchNoExec" title="Branch 4 was not executed"> # </span><span class="branchNoExec" title="Branch 5 was not executed"> # </span>][<span class="branchNoExec" title="Branch 6 was not executed"> # </span><span class="branchNoExec" title="Branch 7 was not executed"> # </span>]
<span class="lineNum">         </span>[<span class="branchNoExec" title="Branch 9 was not executed"> # </span><span class="branchNoExec" title="Branch 10 was not executed"> # </span>][<span class="branchNoExec" title="Branch 11 was not executed"> # </span><span class="branchNoExec" title="Branch 12 was not executed"> # </span>]
<span class="lineNum">         </span>        [<span class="branchNoExec" title="Branch 14 was not executed"> # </span><span class="branchNoExec" title="Branch 15 was not executed"> # </span>]
<span class="lineNum">     789 </span>                :<span class="lineNoCov">          0 :         return 1;</span>
<span class="lineNum">     790 </span>                :            :     }
<span class="lineNum">     791 </span>[<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>][<span class="branchNoExec" title="Branch 2 was not executed"> # </span><span class="branchNoExec" title="Branch 3 was not executed"> # </span>]:<span class="lineNoCov">          0 :     if (V4MAPPED_EQUAL(addr2, addr1)) {</span>
<span class="lineNum">         </span>[<span class="branchNoExec" title="Branch 4 was not executed"> # </span><span class="branchNoExec" title="Branch 5 was not executed"> # </span>][<span class="branchNoExec" title="Branch 6 was not executed"> # </span><span class="branchNoExec" title="Branch 7 was not executed"> # </span>]
<span class="lineNum">         </span>[<span class="branchNoExec" title="Branch 9 was not executed"> # </span><span class="branchNoExec" title="Branch 10 was not executed"> # </span>][<span class="branchNoExec" title="Branch 11 was not executed"> # </span><span class="branchNoExec" title="Branch 12 was not executed"> # </span>]
<span class="lineNum">         </span>        [<span class="branchNoExec" title="Branch 14 was not executed"> # </span><span class="branchNoExec" title="Branch 15 was not executed"> # </span>]
<span class="lineNum">     792 </span>                :<span class="lineNoCov">          0 :         return 1;</span>
<span class="lineNum">     793 </span>                :            :     }
<span class="lineNum">     794 </span>                :            : #endif
<span class="lineNum">     795 </span>                :<span class="lineNoCov">          0 :     return 0; /* not equal */</span>
<span class="lineNum">     796 </span>                :            : }
<a name="797"><span class="lineNum">     797 </span>                :            : </a>
<span class="lineNum">     798 </span>                :            : static apr_status_t parse_network(apr_ipsubnet_t *ipsub, const char *network)
<span class="lineNum">     799 </span>                :<span class="lineCov">          5 : {</span>
<span class="lineNum">     800 </span>                :            :     /* legacy syntax for ip addrs: a.b.c. ==&gt; a.b.c.0/24 for example */
<span class="lineNum">     801 </span>                :            :     int shift;
<span class="lineNum">     802 </span>                :            :     char *s, *t;
<span class="lineNum">     803 </span>                :            :     int octet;
<span class="lineNum">     804 </span>                :            :     char buf[sizeof &quot;255.255.255.255&quot;];
<span class="lineNum">     805 </span>                :            : 
<span class="lineNum">     806 </span>        [<span class="branchCov" title="Branch 1 was taken 5 times"> + </span><span class="branchNoCov" title="Branch 2 was not taken"> - </span>]:<span class="lineCov">          5 :     if (strlen(network) &lt; sizeof buf) {</span>
<span class="lineNum">     807 </span>                :            :         strcpy(buf, network);
<span class="lineNum">     808 </span>                :            :     }
<span class="lineNum">     809 </span>                :            :     else {
<span class="lineNum">     810 </span>                :<span class="lineNoCov">          0 :         return APR_EBADIP;</span>
<span class="lineNum">     811 </span>                :            :     }
<span class="lineNum">     812 </span>                :            : 
<span class="lineNum">     813 </span>                :            :     /* parse components */
<span class="lineNum">     814 </span>                :<span class="lineCov">          5 :     s = buf;</span>
<span class="lineNum">     815 </span>                :<span class="lineCov">          5 :     ipsub-&gt;sub[0] = 0;</span>
<span class="lineNum">     816 </span>                :<span class="lineCov">          5 :     ipsub-&gt;mask[0] = 0;</span>
<span class="lineNum">     817 </span>                :<span class="lineCov">          5 :     shift = 24;</span>
<span class="lineNum">     818 </span>        [<span class="branchCov" title="Branch 0 was taken 13 times"> + </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>]:<span class="lineCov">         16 :     while (*s) {</span>
<span class="lineNum">     819 </span>                :<span class="lineCov">         13 :         t = s;</span>
<span class="lineNum">     820 </span>        [<span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchCov" title="Branch 2 was taken 13 times"> + </span>]:<span class="lineCov">         13 :         if (!apr_isdigit(*t)) {</span>
<span class="lineNum">     821 </span>                :<span class="lineNoCov">          0 :             return APR_EBADIP;</span>
<span class="lineNum">     822 </span>                :            :         }
<span class="lineNum">     823 </span>        [<span class="branchCov" title="Branch 1 was taken 24 times"> + </span><span class="branchCov" title="Branch 2 was taken 13 times"> + </span>]:<span class="lineCov">         37 :         while (apr_isdigit(*t)) {</span>
<span class="lineNum">     824 </span>                :<span class="lineCov">         24 :             ++t;</span>
<span class="lineNum">     825 </span>                :            :         }
<span class="lineNum">     826 </span>        [<span class="branchCov" title="Branch 0 was taken 8 times"> + </span><span class="branchCov" title="Branch 1 was taken 5 times"> + </span>]:<span class="lineCov">         13 :         if (*t == '.') {</span>
<span class="lineNum">     827 </span>                :<span class="lineCov">          8 :             *t++ = 0;</span>
<span class="lineNum">     828 </span>                :            :         }
<span class="lineNum">     829 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 5 times"> + </span>]:<span class="lineCov">          5 :         else if (*t) {</span>
<span class="lineNum">     830 </span>                :<span class="lineNoCov">          0 :             return APR_EBADIP;</span>
<span class="lineNum">     831 </span>                :            :         }
<span class="lineNum">     832 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 12 times"> + </span>]:<span class="lineCov">         13 :         if (shift &lt; 0) {</span>
<span class="lineNum">     833 </span>                :<span class="lineCov">          1 :             return APR_EBADIP;</span>
<span class="lineNum">     834 </span>                :            :         }
<span class="lineNum">     835 </span>                :            :         octet = atoi(s);
<span class="lineNum">     836 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 11 times"> + </span>]:<span class="lineCov">         12 :         if (octet &lt; 0 || octet &gt; 255) {</span>
<span class="lineNum">     837 </span>                :<span class="lineCov">          1 :             return APR_EBADIP;</span>
<span class="lineNum">     838 </span>                :            :         }
<span class="lineNum">     839 </span>                :<span class="lineCov">         11 :         ipsub-&gt;sub[0] |= octet &lt;&lt; shift;</span>
<span class="lineNum">     840 </span>                :<span class="lineCov">         11 :         ipsub-&gt;mask[0] |= 0xFFUL &lt;&lt; shift;</span>
<span class="lineNum">     841 </span>                :<span class="lineCov">         11 :         s = t;</span>
<span class="lineNum">     842 </span>                :<span class="lineCov">         11 :         shift -= 8;</span>
<span class="lineNum">     843 </span>                :            :     }
<span class="lineNum">     844 </span>        [<span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchCov" title="Branch 2 was taken 3 times"> + </span>]:<span class="lineCov">          3 :     ipsub-&gt;sub[0] = ntohl(ipsub-&gt;sub[0]);</span>
<span class="lineNum">     845 </span>        [<span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchCov" title="Branch 2 was taken 3 times"> + </span>]:<span class="lineCov">          3 :     ipsub-&gt;mask[0] = ntohl(ipsub-&gt;mask[0]);</span>
<span class="lineNum">     846 </span>                :<span class="lineCov">          3 :     ipsub-&gt;family = AF_INET;</span>
<span class="lineNum">     847 </span>                :<span class="lineCov">          5 :     return APR_SUCCESS;</span>
<span class="lineNum">     848 </span>                :            : }
<span class="lineNum">     849 </span>                :            : 
<span class="lineNum">     850 </span>                :            : /* return values:
<span class="lineNum">     851 </span>                :            :  * APR_EINVAL     not an IP address; caller should see if it is something else
<span class="lineNum">     852 </span>                :            :  * APR_BADIP      IP address portion is is not valid
<span class="lineNum">     853 </span>                :            :  * APR_BADMASK    mask portion is not valid
<span class="lineNum">     854 </span>                :            :  */
<span class="lineNum">     855 </span>                :            : 
<span class="lineNum">     856 </span>                :            : static apr_status_t parse_ip(apr_ipsubnet_t *ipsub, const char *ipstr, int network_allowed)
<span class="lineNum">     857 </span>                :            : {
<span class="lineNum">     858 </span>                :            :     /* supported flavors of IP:
<span class="lineNum">     859 </span>                :            :      *
<span class="lineNum">     860 </span>                :            :      * . IPv6 numeric address string (e.g., &quot;fe80::1&quot;)
<span class="lineNum">     861 </span>                :            :      * 
<span class="lineNum">     862 </span>                :            :      *   IMPORTANT: Don't store IPv4-mapped IPv6 address as an IPv6 address.
<span class="lineNum">     863 </span>                :            :      *
<span class="lineNum">     864 </span>                :            :      * . IPv4 numeric address string (e.g., &quot;127.0.0.1&quot;)
<span class="lineNum">     865 </span>                :            :      *
<span class="lineNum">     866 </span>                :            :      * . IPv4 network string (e.g., &quot;9.67&quot;)
<span class="lineNum">     867 </span>                :            :      *
<span class="lineNum">     868 </span>                :            :      *   IMPORTANT: This network form is only allowed if network_allowed is on.
<span class="lineNum">     869 </span>                :            :      */
<span class="lineNum">     870 </span>                :            :     int rc;
<a name="871"><span class="lineNum">     871 </span>                :            : </a>
<span class="lineNum">     872 </span>                :            : #if APR_HAVE_IPV6
<span class="lineNum">     873 </span>                :<span class="lineCov">         49 :     rc = apr_inet_pton(AF_INET6, ipstr, ipsub-&gt;sub);</span>
<span class="lineNum">     874 </span>        [<span class="branchCov" title="Branch 0 was taken 14 times"> + </span><span class="branchCov" title="Branch 1 was taken 35 times"> + </span>]:<span class="lineCov">         49 :     if (rc == 1) {</span>
<span class="lineNum">     875 </span>[<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchCov" title="Branch 1 was taken 11 times"> + </span>][<span class="branchCov" title="Branch 2 was taken 3 times"> + </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span>]:<span class="lineCov">         14 :         if (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)ipsub-&gt;sub)) {</span>
<span class="lineNum">         </span>[<span class="branchCov" title="Branch 5 was taken 3 times"> + </span><span class="branchNoCov" title="Branch 6 was not taken"> - </span>][<span class="branchCov" title="Branch 7 was taken 1 time"> + </span><span class="branchCov" title="Branch 8 was taken 2 times"> + </span>]
<span class="lineNum">     876 </span>                :            :             /* apr_ipsubnet_test() assumes that we don't create IPv4-mapped IPv6
<span class="lineNum">     877 </span>                :            :              * addresses; this of course forces the user to specify IPv4 addresses
<span class="lineNum">     878 </span>                :            :              * in a.b.c.d style instead of ::ffff:a.b.c.d style.
<span class="lineNum">     879 </span>                :            :              */
<span class="lineNum">     880 </span>                :<span class="lineCov">          1 :             return APR_EBADIP;</span>
<span class="lineNum">     881 </span>                :            :         }
<span class="lineNum">     882 </span>                :<span class="lineCov">         13 :         ipsub-&gt;family = AF_INET6;</span>
<span class="lineNum">     883 </span>                :            :     }
<span class="lineNum">     884 </span>                :            :     else
<span class="lineNum">     885 </span>                :            : #endif
<span class="lineNum">     886 </span>                :            :     {
<span class="lineNum">     887 </span>                :<span class="lineCov">         35 :         rc = apr_inet_pton(AF_INET, ipstr, ipsub-&gt;sub);</span>
<span class="lineNum">     888 </span>        [<span class="branchCov" title="Branch 0 was taken 28 times"> + </span><span class="branchCov" title="Branch 1 was taken 7 times"> + </span>]:<span class="lineCov">         35 :         if (rc == 1) {</span>
<span class="lineNum">     889 </span>                :<span class="lineCov">         28 :             ipsub-&gt;family = AF_INET;</span>
<span class="lineNum">     890 </span>                :            :         }
<span class="lineNum">     891 </span>                :            :     }
<span class="lineNum">     892 </span>        [<span class="branchCov" title="Branch 0 was taken 7 times"> + </span><span class="branchCov" title="Branch 1 was taken 41 times"> + </span>]:<span class="lineCov">         48 :     if (rc != 1) {</span>
<span class="lineNum">     893 </span>        [<span class="branchCov" title="Branch 0 was taken 5 times"> + </span><span class="branchCov" title="Branch 1 was taken 2 times"> + </span>]:<span class="lineCov">          7 :         if (network_allowed) {</span>
<span class="lineNum">     894 </span>                :<span class="lineCov">          5 :             return parse_network(ipsub, ipstr);</span>
<span class="lineNum">     895 </span>                :            :         }
<span class="lineNum">     896 </span>                :            :         else {
<span class="lineNum">     897 </span>                :<span class="lineCov">          2 :             return APR_EBADIP;</span>
<span class="lineNum">     898 </span>                :            :         }
<span class="lineNum">     899 </span>                :            :     }
<span class="lineNum">     900 </span>                :<span class="lineCov">         41 :     return APR_SUCCESS;</span>
<span class="lineNum">     901 </span>                :            : }
<span class="lineNum">     902 </span>                :            : 
<span class="lineNum">     903 </span>                :            : static int looks_like_ip(const char *ipstr)
<span class="lineNum">     904 </span>                :            : {
<span class="lineNum">     905 </span>        [<span class="branchCov" title="Branch 1 was taken 14 times"> + </span><span class="branchCov" title="Branch 2 was taken 36 times"> + </span>]:<span class="lineCov">         50 :     if (strchr(ipstr, ':')) {</span>
<span class="lineNum">     906 </span>                :            :         /* definitely not a hostname; assume it is intended to be an IPv6 address */
<span class="lineNum">     907 </span>                :<span class="lineCov">         14 :         return 1;</span>
<span class="lineNum">     908 </span>                :            :     }
<span class="lineNum">     909 </span>                :            : 
<span class="lineNum">     910 </span>                :            :     /* simple IPv4 address string check */
<span class="lineNum">     911 </span>[<span class="branchCov" title="Branch 0 was taken 96 times"> + </span><span class="branchCov" title="Branch 1 was taken 280 times"> + </span>][<span class="branchCov" title="Branch 3 was taken 244 times"> + </span><span class="branchCov" title="Branch 4 was taken 36 times"> + </span>]:<span class="lineCov">        376 :     while ((*ipstr == '.') || apr_isdigit(*ipstr))</span>
<span class="lineNum">     912 </span>                :<span class="lineCov">        340 :         ipstr++;</span>
<span class="lineNum">     913 </span>                :<span class="lineCov">         36 :     return (*ipstr == '\0');</span>
<span class="lineNum">     914 </span>                :            : }
<span class="lineNum">     915 </span>                :            : 
<span class="lineNum">     916 </span>                :            : static void fix_subnet(apr_ipsubnet_t *ipsub)
<span class="lineNum">     917 </span>                :            : {
<span class="lineNum">     918 </span>                :            :     /* in case caller specified more bits in network address than are
<span class="lineNum">     919 </span>                :            :      * valid according to the mask, turn off the extra bits
<span class="lineNum">     920 </span>                :            :      */
<span class="lineNum">     921 </span>                :            :     int i;
<span class="lineNum">     922 </span>                :            : 
<span class="lineNum">     923 </span>        [<span class="branchCov" title="Branch 0 was taken 136 times"> + </span><span class="branchCov" title="Branch 1 was taken 34 times"> + </span>]:<span class="lineCov">        170 :     for (i = 0; i &lt; sizeof ipsub-&gt;mask / sizeof(apr_int32_t); i++) {</span>
<span class="lineNum">     924 </span>                :<span class="lineCov">        136 :         ipsub-&gt;sub[i] &amp;= ipsub-&gt;mask[i];</span>
<span class="lineNum">     925 </span>                :            :     }
<span class="lineNum">     926 </span>                :            : }
<span class="lineNum">     927 </span>                :            : 
<span class="lineNum">     928 </span>                :            : /* be sure not to store any IPv4 address as a v4-mapped IPv6 address */
<span class="lineNum">     929 </span>                :            : APR_DECLARE(apr_status_t) apr_ipsubnet_create(apr_ipsubnet_t **ipsub, const char *ipstr, 
<span class="lineNum">     930 </span>                :            :                                               const char *mask_or_numbits, apr_pool_t *p)
<span class="lineNum">     931 </span>                :<span class="lineCov">         50 : {</span>
<span class="lineNum">     932 </span>                :            :     apr_status_t rv;
<span class="lineNum">     933 </span>                :            :     char *endptr;
<span class="lineNum">     934 </span>                :<span class="lineCov">         50 :     long bits, maxbits = 32;</span>
<span class="lineNum">     935 </span>                :            : 
<span class="lineNum">     936 </span>                :            :     /* filter out stuff which doesn't look remotely like an IP address; this helps 
<span class="lineNum">     937 </span>                :            :      * callers like mod_access which have a syntax allowing hostname or IP address;
<span class="lineNum">     938 </span>                :            :      * APR_EINVAL tells the caller that it was probably not intended to be an IP
<span class="lineNum">     939 </span>                :            :      * address
<span class="lineNum">     940 </span>                :            :      */
<span class="lineNum">     941 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 49 times"> + </span>]:<span class="lineCov">         50 :     if (!looks_like_ip(ipstr)) {</span>
<span class="lineNum">     942 </span>                :<span class="lineCov">          1 :         return APR_EINVAL;</span>
<span class="lineNum">     943 </span>                :            :     }
<span class="lineNum">     944 </span>                :            : 
<span class="lineNum">     945 </span>                :<span class="lineCov">         49 :     *ipsub = apr_pcalloc(p, sizeof(apr_ipsubnet_t));</span>
<span class="lineNum">     946 </span>                :            : 
<span class="lineNum">     947 </span>                :            :     /* assume ipstr is an individual IP address, not a subnet */
<span class="lineNum">     948 </span>                :<span class="lineCov">         49 :     memset((*ipsub)-&gt;mask, 0xFF, sizeof (*ipsub)-&gt;mask);</span>
<span class="lineNum">     949 </span>                :            : 
<span class="lineNum">     950 </span>                :<span class="lineCov">         98 :     rv = parse_ip(*ipsub, ipstr, mask_or_numbits == NULL);</span>
<span class="lineNum">     951 </span>        [<span class="branchCov" title="Branch 0 was taken 5 times"> + </span><span class="branchCov" title="Branch 1 was taken 44 times"> + </span>]:<span class="lineCov">         49 :     if (rv != APR_SUCCESS) {</span>
<span class="lineNum">     952 </span>                :<span class="lineCov">          5 :         return rv;</span>
<span class="lineNum">     953 </span>                :            :     }
<span class="lineNum">     954 </span>                :            : 
<span class="lineNum">     955 </span>        [<span class="branchCov" title="Branch 0 was taken 28 times"> + </span><span class="branchCov" title="Branch 1 was taken 16 times"> + </span>]:<span class="lineCov">         44 :     if (mask_or_numbits) {</span>
<span class="lineNum">     956 </span>                :            : #if APR_HAVE_IPV6
<span class="lineNum">     957 </span>        [<span class="branchCov" title="Branch 0 was taken 12 times"> + </span><span class="branchCov" title="Branch 1 was taken 16 times"> + </span>]:<span class="lineCov">         28 :         if ((*ipsub)-&gt;family == AF_INET6) {</span>
<span class="lineNum">     958 </span>                :<span class="lineCov">         12 :             maxbits = 128;</span>
<span class="lineNum">     959 </span>                :            :         }
<span class="lineNum">     960 </span>                :            : #endif
<span class="lineNum">     961 </span>                :<span class="lineCov">         28 :         bits = strtol(mask_or_numbits, &amp;endptr, 10);</span>
<span class="lineNum">     962 </span>[<span class="branchCov" title="Branch 0 was taken 17 times"> + </span><span class="branchCov" title="Branch 1 was taken 11 times"> + </span>][<span class="branchCov" title="Branch 2 was taken 15 times"> + </span><span class="branchCov" title="Branch 3 was taken 2 times"> + </span>]:<span class="lineCov">         43 :         if (*endptr == '\0' &amp;&amp; bits &gt; 0 &amp;&amp; bits &lt;= maxbits) {</span>
<span class="lineNum">     963 </span>                :            :             /* valid num-bits string; fill in mask appropriately */
<span class="lineNum">     964 </span>                :<span class="lineCov">         15 :             int cur_entry = 0;</span>
<span class="lineNum">     965 </span>                :            :             apr_int32_t cur_bit_value;
<span class="lineNum">     966 </span>                :            : 
<span class="lineNum">     967 </span>                :<span class="lineCov">         15 :             memset((*ipsub)-&gt;mask, 0, sizeof (*ipsub)-&gt;mask);</span>
<span class="lineNum">     968 </span>        [<span class="branchCov" title="Branch 0 was taken 4 times"> + </span><span class="branchCov" title="Branch 1 was taken 15 times"> + </span>]:<span class="lineCov">         19 :             while (bits &gt; 32) {</span>
<span class="lineNum">     969 </span>                :<span class="lineCov">          4 :                 (*ipsub)-&gt;mask[cur_entry] = 0xFFFFFFFF; /* all 32 bits */</span>
<span class="lineNum">     970 </span>                :<span class="lineCov">          4 :                 bits -= 32;</span>
<span class="lineNum">     971 </span>                :<span class="lineCov">          4 :                 ++cur_entry;</span>
<span class="lineNum">     972 </span>                :            :             }
<span class="lineNum">     973 </span>                :<span class="lineCov">         15 :             cur_bit_value = 0x80000000;</span>
<span class="lineNum">     974 </span>        [<span class="branchCov" title="Branch 0 was taken 210 times"> + </span><span class="branchCov" title="Branch 1 was taken 15 times"> + </span>]:<span class="lineCov">        225 :             while (bits) {</span>
<span class="lineNum">     975 </span>                :<span class="lineCov">        210 :                 (*ipsub)-&gt;mask[cur_entry] |= cur_bit_value;</span>
<span class="lineNum">     976 </span>                :<span class="lineCov">        210 :                 --bits;</span>
<span class="lineNum">     977 </span>                :<span class="lineCov">        210 :                 cur_bit_value /= 2;</span>
<span class="lineNum">     978 </span>                :            :             }
<span class="lineNum">     979 </span>        [<span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchCov" title="Branch 2 was taken 15 times"> + </span>]:<span class="lineCov">         15 :             (*ipsub)-&gt;mask[cur_entry] = htonl((*ipsub)-&gt;mask[cur_entry]);</span>
<span class="lineNum">     980 </span>                :            :         }
<span class="lineNum">     981 </span>[<span class="branchCov" title="Branch 1 was taken 4 times"> + </span><span class="branchCov" title="Branch 2 was taken 9 times"> + </span>][<span class="branchCov" title="Branch 3 was taken 1 time"> + </span><span class="branchCov" title="Branch 4 was taken 3 times"> + </span>]:<span class="lineCov">         13 :         else if (apr_inet_pton(AF_INET, mask_or_numbits, (*ipsub)-&gt;mask) == 1 &amp;&amp;</span>
<span class="lineNum">     982 </span>                :            :             (*ipsub)-&gt;family == AF_INET) {
<span class="lineNum">     983 </span>                :            :             /* valid IPv4 netmask */
<span class="lineNum">     984 </span>                :            :         }
<span class="lineNum">     985 </span>                :            :         else {
<span class="lineNum">     986 </span>                :<span class="lineCov">         10 :             return APR_EBADMASK;</span>
<span class="lineNum">     987 </span>                :            :         }
<span class="lineNum">     988 </span>                :            :     }
<span class="lineNum">     989 </span>                :            : 
<span class="lineNum">     990 </span>                :<span class="lineCov">         34 :     fix_subnet(*ipsub);</span>
<span class="lineNum">     991 </span>                :            : 
<span class="lineNum">     992 </span>                :<span class="lineCov">         50 :     return APR_SUCCESS;</span>
<span class="lineNum">     993 </span>                :            : }
<a name="994"><span class="lineNum">     994 </span>                :            : </a>
<span class="lineNum">     995 </span>                :            : APR_DECLARE(int) apr_ipsubnet_test(apr_ipsubnet_t *ipsub, apr_sockaddr_t *sa)
<span class="lineNum">     996 </span>                :<span class="lineCov">        124 : {</span>
<span class="lineNum">     997 </span>                :            : #if APR_HAVE_IPV6
<span class="lineNum">     998 </span>                :            :     /* XXX This line will segv on Win32 build with APR_HAVE_IPV6,
<span class="lineNum">     999 </span>                :            :      * but without the IPV6 drivers installed.
<span class="lineNum">    1000 </span>                :            :      */
<span class="lineNum">    1001 </span>        [<span class="branchCov" title="Branch 0 was taken 114 times"> + </span><span class="branchCov" title="Branch 1 was taken 10 times"> + </span>]:<span class="lineCov">        124 :     if (sa-&gt;sa.sin.sin_family == AF_INET) {</span>
<span class="lineNum">    1002 </span>[<span class="branchCov" title="Branch 0 was taken 114 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>][<span class="branchCov" title="Branch 2 was taken 17 times"> + </span><span class="branchCov" title="Branch 3 was taken 97 times"> + </span>]:<span class="lineCov">        114 :         if (ipsub-&gt;family == AF_INET &amp;&amp;</span>
<span class="lineNum">    1003 </span>                :            :             ((sa-&gt;sa.sin.sin_addr.s_addr &amp; ipsub-&gt;mask[0]) == ipsub-&gt;sub[0])) {
<span class="lineNum">    1004 </span>                :<span class="lineCov">         17 :             return 1;</span>
<span class="lineNum">    1005 </span>                :            :         }
<span class="lineNum">    1006 </span>                :            :     }
<span class="lineNum">    1007 </span>[<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 8 times"> + </span>][<span class="branchCov" title="Branch 2 was taken 2 times"> + </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span>]:<span class="lineCov">         10 :     else if (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)sa-&gt;ipaddr_ptr)) {</span>
<span class="lineNum">         </span>[<span class="branchCov" title="Branch 5 was taken 2 times"> + </span><span class="branchNoCov" title="Branch 6 was not taken"> - </span>][<span class="branchCov" title="Branch 7 was taken 2 times"> + </span><span class="branchNoCov" title="Branch 8 was not taken"> - </span>]
<span class="lineNum">    1008 </span>[<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>][<span class="branchCov" title="Branch 2 was taken 2 times"> + </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span>]:<span class="lineCov">          2 :         if (ipsub-&gt;family == AF_INET &amp;&amp;</span>
<span class="lineNum">    1009 </span>                :            :             (((apr_uint32_t *)sa-&gt;ipaddr_ptr)[3] &amp; ipsub-&gt;mask[0]) == ipsub-&gt;sub[0]) {
<span class="lineNum">    1010 </span>                :<span class="lineCov">          2 :             return 1;</span>
<span class="lineNum">    1011 </span>                :            :         }
<span class="lineNum">    1012 </span>                :            :     }
<span class="lineNum">    1013 </span>                :            :     else {
<span class="lineNum">    1014 </span>                :<span class="lineCov">          8 :         apr_uint32_t *addr = (apr_uint32_t *)sa-&gt;ipaddr_ptr;</span>
<span class="lineNum">    1015 </span>                :            : 
<span class="lineNum">    1016 </span>[<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchCov" title="Branch 1 was taken 5 times"> + </span>][<span class="branchCov" title="Branch 2 was taken 3 times"> + </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span>]:<span class="lineCov">          8 :         if ((addr[0] &amp; ipsub-&gt;mask[0]) == ipsub-&gt;sub[0] &amp;&amp;</span>
<span class="lineNum">         </span>[<span class="branchCov" title="Branch 4 was taken 3 times"> + </span><span class="branchNoCov" title="Branch 5 was not taken"> - </span>][<span class="branchCov" title="Branch 6 was taken 3 times"> + </span><span class="branchNoCov" title="Branch 7 was not taken"> - </span>]
<span class="lineNum">    1017 </span>                :            :             (addr[1] &amp; ipsub-&gt;mask[1]) == ipsub-&gt;sub[1] &amp;&amp;
<span class="lineNum">    1018 </span>                :            :             (addr[2] &amp; ipsub-&gt;mask[2]) == ipsub-&gt;sub[2] &amp;&amp;
<span class="lineNum">    1019 </span>                :            :             (addr[3] &amp; ipsub-&gt;mask[3]) == ipsub-&gt;sub[3]) {
<span class="lineNum">    1020 </span>                :<span class="lineCov">          3 :             return 1;</span>
<span class="lineNum">    1021 </span>                :            :         }
<span class="lineNum">    1022 </span>                :            :     }
<span class="lineNum">    1023 </span>                :            : #else
<span class="lineNum">    1024 </span>                :            :     if ((sa-&gt;sa.sin.sin_addr.s_addr &amp; ipsub-&gt;mask[0]) == ipsub-&gt;sub[0]) {
<span class="lineNum">    1025 </span>                :            :         return 1;
<span class="lineNum">    1026 </span>                :            :     }
<span class="lineNum">    1027 </span>                :            : #endif /* APR_HAVE_IPV6 */
<span class="lineNum">    1028 </span>                :<span class="lineCov">        124 :     return 0; /* no match */</span>
<span class="lineNum">    1029 </span>                :            : }
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.9</a></td></tr>
  </table>
  <br>

</body>
</html>
